summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2022-01-19 16:13:23 -0500
committerBernard Xiong <[email protected]>2022-01-20 20:50:24 +0800
commitadd72f1d7cc32a8d302f6e5549b82b4ce06a5a9a (patch)
tree91947dea0ebf806e7fa527bcc976ebcbe1291c30
parentb67f34b09713daf8597cef9dac7f8591a900dee0 (diff)
[dfs][posix] add creat()
-rw-r--r--components/dfs/src/dfs_posix.c16
-rw-r--r--components/libc/compilers/common/extension/fcntl.h4
2 files changed, 18 insertions, 2 deletions
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c
index 5b26f190ce..3008a06da5 100644
--- a/components/dfs/src/dfs_posix.c
+++ b/components/dfs/src/dfs_posix.c
@@ -7,6 +7,7 @@
* Date Author Notes
* 2009-05-27 Yi.qiu The first version
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
+ * 2022-01-19 Meco Man add creat()
*/
#include <dfs_file.h>
@@ -57,6 +58,21 @@ int open(const char *file, int flags, ...)
RTM_EXPORT(open);
/**
+ * this function is a POSIX compliant version,
+ * which will create a new file or rewrite an existing one
+ *
+ * @param path the path name of file.
+ * @param mode the file permission bits to be used in creating the file (not used, can be 0)
+ *
+ * @return the non-negative integer on successful open, others for failed.
+ */
+int creat(const char *path, mode_t mode)
+{
+ return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
+}
+RTM_EXPORT(creat);
+
+/**
* this function is a POSIX compliant version, which will close the open
* file descriptor.
*
diff --git a/components/libc/compilers/common/extension/fcntl.h b/components/libc/compilers/common/extension/fcntl.h
index 83c3ec0b6b..ac642abcbb 100644
--- a/components/libc/compilers/common/extension/fcntl.h
+++ b/components/libc/compilers/common/extension/fcntl.h
@@ -11,7 +11,7 @@
#ifndef __FCNTL_H__
#define __FCNTL_H__
-#include <sys/types.h>
+#include "sys/types.h"
#define O_RDONLY 00
#define O_WRONLY 01
@@ -66,6 +66,6 @@
int open(const char *file, int flags, ...);
int fcntl(int fildes, int cmd, ...);
-int creat(const char *, mode_t);
+int creat(const char *path, mode_t mode);
#endif