MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / open

Function open

components/dfs/dfs_v2/src/dfs_posix.c:48–88  ·  view source on GitHub ↗

* this function is a POSIX compliant version, which will open a file and * return a file descriptor according specified flags. * * @param file the path name of file. * @param flags the file open flags. Common values include: * - Access modes (mutually exclusive): * - `O_RDONLY`: Open for read-only access. * - `O_WRONLY`: Open for write-only access. * - `O_RDWR`:

Source from the content-addressed store, hash-verified

46 * @return the non-negative integer on successful open, others for failed.
47 */
48int open(const char *file, int flags, ...)
49{
50 int fd, result;
51 struct dfs_file *df = RT_NULL;
52 mode_t mode = 0;
53
54 if (file == NULL)
55 {
56 rt_set_errno(-EBADF);
57 return -1;
58 }
59
60 if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE)
61 {
62 va_list ap;
63 va_start(ap, flags);
64 mode = va_arg(ap, mode_t);
65 va_end(ap);
66 }
67
68 fd = fd_new();
69 if (fd >= 0)
70 {
71 df = fd_get(fd);
72 }
73 else
74 {
75 rt_set_errno(-RT_ERROR);
76 return RT_NULL;
77 }
78
79 result = dfs_file_open(df, file, flags, mode);
80 if (result < 0)
81 {
82 fd_release(fd);
83 rt_set_errno(result);
84 return -1;
85 }
86
87 return fd;
88}
89RTM_EXPORT(open);
90
91#ifndef AT_FDCWD

Callers 3

openatFunction · 0.70
creatFunction · 0.70
dfs_devfs_device_addFunction · 0.50

Calls 5

rt_set_errnoFunction · 0.85
fd_newFunction · 0.70
fd_getFunction · 0.70
dfs_file_openFunction · 0.70
fd_releaseFunction · 0.70

Tested by

no test coverage detected