lib/posix: Add support for open flags to open(...)
The fs_open flags has been changed to accept open flags, which requires changes to open(...) to support the new flags. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
deb1694c3c
commit
49ab2099f3
2 changed files with 33 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_FCNTL_H_
|
||||
|
||||
#define O_CREAT 0x0200
|
||||
#define O_APPEND 0x0400
|
||||
#define O_EXCL 0x0800
|
||||
#define O_NONBLOCK 0x4000
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <posix/dirent.h>
|
||||
#include <string.h>
|
||||
#include <sys/fdtable.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <fs/fs.h>
|
||||
|
||||
BUILD_ASSERT(PATH_MAX >= MAX_FILE_NAME, "PATH_MAX is less than MAX_FILE_NAME");
|
||||
|
||||
|
@ -54,6 +57,29 @@ static inline void posix_fs_free_obj(struct posix_fs_desc *ptr)
|
|||
ptr->used = false;
|
||||
}
|
||||
|
||||
static int posix_mode_to_zephyr(int mf)
|
||||
{
|
||||
int mode = (mf & O_CREAT) ? FS_O_CREATE : 0;
|
||||
|
||||
mode |= (mf & O_APPEND) ? FS_O_APPEND : 0;
|
||||
|
||||
switch (mf & O_ACCMODE) {
|
||||
case O_RDONLY:
|
||||
mode |= FS_O_READ;
|
||||
break;
|
||||
case O_WRONLY:
|
||||
mode |= FS_O_WRITE;
|
||||
break;
|
||||
case O_RDWR:
|
||||
mode |= FS_O_RDWR;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open a file.
|
||||
*
|
||||
|
@ -63,8 +89,11 @@ int open(const char *name, int flags, ...)
|
|||
{
|
||||
int rc, fd;
|
||||
struct posix_fs_desc *ptr = NULL;
|
||||
int zmode = posix_mode_to_zephyr(flags);
|
||||
|
||||
ARG_UNUSED(flags);
|
||||
if (zmode < 0) {
|
||||
return zmode;
|
||||
}
|
||||
|
||||
fd = z_reserve_fd();
|
||||
if (fd < 0) {
|
||||
|
@ -80,7 +109,8 @@ int open(const char *name, int flags, ...)
|
|||
|
||||
(void)memset(&ptr->file, 0, sizeof(ptr->file));
|
||||
|
||||
rc = fs_open(&ptr->file, name);
|
||||
rc = fs_open(&ptr->file, name, zmode);
|
||||
|
||||
if (rc < 0) {
|
||||
posix_fs_free_obj(ptr);
|
||||
z_free_fd(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue