!768 feature: C库补充access、remove接口
Merge pull request !768 from Zhaotianyu/20220806fs_add
This commit is contained in:
commit
ae692bfbc4
|
@ -28,22 +28,20 @@
|
|||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "los_config.h"
|
||||
#include "stdarg.h"
|
||||
#include "dirent.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef LOSCFG_LIBC_MUSL_FS
|
||||
#include "los_fs.h"
|
||||
#else
|
||||
#include "sys/stat.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_LIBC_MUSL_FS
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
|
@ -161,6 +159,23 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
|||
return LOS_Pwrite(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
|
||||
return 0;
|
||||
}
|
||||
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* #ifdef LOSCFG_FS_VFS */
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
|
@ -275,4 +290,9 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _ADAPT_SYS_STAT_H
|
||||
#define _ADAPT_SYS_STAT_H
|
||||
|
||||
#include <sys/features.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define S_IFMT 0170000
|
||||
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFBLK 0060000
|
||||
#define S_IFREG 0100000
|
||||
#define S_IFIFO 0010000
|
||||
#define S_IFLNK 0120000
|
||||
#define S_IFSOCK 0140000
|
||||
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
||||
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
|
||||
|
||||
#ifndef S_IRUSR
|
||||
#define S_ISUID 04000
|
||||
#define S_ISGID 02000
|
||||
#define S_ISVTX 01000
|
||||
#define S_IRUSR 0400
|
||||
#define S_IWUSR 0200
|
||||
#define S_IXUSR 0100
|
||||
#define S_IRWXU 0700
|
||||
#define S_IRGRP 0040
|
||||
#define S_IWGRP 0020
|
||||
#define S_IXGRP 0010
|
||||
#define S_IRWXG 0070
|
||||
#define S_IROTH 0004
|
||||
#define S_IWOTH 0002
|
||||
#define S_IXOTH 0001
|
||||
#define S_IRWXO 0007
|
||||
#endif
|
||||
|
||||
#define st_atime st_atim.tv_sec
|
||||
#define st_mtime st_mtim.tv_sec
|
||||
#define st_ctime st_ctim.tv_sec
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev;
|
||||
int __st_dev_padding;
|
||||
long __st_ino_truncated;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
int __st_rdev_padding;
|
||||
off_t st_size;
|
||||
blksize_t st_blksize;
|
||||
blkcnt_t st_blocks;
|
||||
struct {
|
||||
long tv_sec;
|
||||
long tv_nsec;
|
||||
} __st_atim32, __st_mtim32, __st_ctim32;
|
||||
ino_t st_ino;
|
||||
struct timespec st_atim;
|
||||
struct timespec st_mtim;
|
||||
struct timespec st_ctim;
|
||||
};
|
||||
|
||||
int stat(const char *__restrict, struct stat *__restrict);
|
||||
int fstat(int, struct stat *);
|
||||
int mkdir(const char *, mode_t);
|
||||
|
||||
#if defined(_GNU_SOURCE)
|
||||
#define stat64 stat
|
||||
#define fstat64 fstat
|
||||
#define blkcnt64_t blkcnt_t
|
||||
#define fsblkcnt64_t fsblkcnt_t
|
||||
#define fsfilcnt64_t fsfilcnt_t
|
||||
#define ino64_t ino_t
|
||||
#define off64_t off_t
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_ADAPT_SYS_STAT_H */
|
|
@ -27,16 +27,17 @@
|
|||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "los_config.h"
|
||||
#include "stdio.h"
|
||||
#include "stdarg.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB_FS
|
||||
#include "los_fs.h"
|
||||
#else
|
||||
#include "sys/stat.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB_FS
|
||||
|
@ -167,6 +168,33 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
|||
return LOS_Pwrite(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
|
||||
return 0;
|
||||
}
|
||||
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
int ret = unlink(filename);
|
||||
if (ret == -EISDIR) {
|
||||
ret = rmdir(filename);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* #ifdef LOSCFG_FS_VFS */
|
||||
|
||||
int _open(const char *path, int oflag, ...)
|
||||
|
@ -209,4 +237,14 @@ int _stat(const char *path, struct stat *buf)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue