Changeset b19e892 in mainline for uspace/lib/posix
- Timestamp:
- 2017-04-02T10:39:13Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c4cf0d
- Parents:
- 80743a1
- Location:
- uspace/lib/posix
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/include/posix/fcntl.h
r80743a1 rb19e892 41 41 42 42 #include "sys/types.h" 43 #include "libc/fcntl.h"44 43 #include "errno.h" 44 45 #undef O_CREAT 46 #undef O_EXCL 47 #undef O_TRUNC 48 #undef O_APPEND 49 #undef O_RDONLY 50 #undef O_RDWR 51 #undef O_WRONLY 52 #define O_CREAT 1 53 #define O_EXCL 2 54 #define O_TRUNC 4 55 #define O_APPEND 8 56 #define O_RDONLY 16 57 #define O_RDWR 32 58 #define O_WRONLY 64 45 59 46 60 /* Mask for file access modes. */ -
uspace/lib/posix/source/fcntl.c
r80743a1 rb19e892 100 100 * 101 101 * @param pathname Path to the file. 102 * @param flags Access mode flags.102 * @param posix_flags Access mode flags. 103 103 */ 104 int posix_open(const char *pathname, int flags, ...)104 int posix_open(const char *pathname, int posix_flags, ...) 105 105 { 106 mode_t mode = 0; 107 if ((flags & O_CREAT) > 0) { 106 int rc; 107 mode_t posix_mode = 0; 108 if (posix_flags & O_CREAT) { 108 109 va_list args; 109 va_start(args, flags);110 mode = va_arg(args, mode_t);110 va_start(args, posix_flags); 111 posix_mode = va_arg(args, mode_t); 111 112 va_end(args); 113 (void) posix_mode; 112 114 } 113 115 114 return negerrno(open, pathname, flags, mode); 116 if (((posix_flags & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) || 117 ((posix_flags & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) || 118 ((posix_flags & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) || 119 ((posix_flags & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) { 120 errno = EINVAL; 121 return -1; 122 } 123 124 int flags = WALK_REGULAR; 125 if (posix_flags & O_CREAT) { 126 if (posix_flags & O_EXCL) 127 flags |= WALK_MUST_CREATE; 128 else 129 flags |= WALK_MAY_CREATE; 130 } 131 132 int mode = 133 ((posix_flags & O_RDWR) ? MODE_READ | MODE_WRITE : 0) | 134 ((posix_flags & O_RDONLY) ? MODE_READ : 0) | 135 ((posix_flags & O_WRONLY) ? MODE_WRITE : 0) | 136 ((posix_flags & O_APPEND) ? MODE_APPEND : 0); 137 138 int file = rcerrno(vfs_lookup, pathname, flags); 139 if (file < 0) 140 return -1; 141 142 rc = rcerrno(vfs_open, file, mode); 143 if (rc != EOK) { 144 close (file); 145 return -1; 146 } 147 148 if (posix_flags & O_TRUNC) { 149 if (posix_flags & (O_RDWR | O_WRONLY)) { 150 rc = rcerrno(vfs_resize, file, 0); 151 if (rc != EOK) { 152 close(file); 153 return -1; 154 } 155 } 156 } 157 158 return file; 115 159 } 116 160 117 161 /** @} 118 162 */ 163 -
uspace/lib/posix/source/stdlib.c
r80743a1 rb19e892 431 431 } 432 432 433 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);433 fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 434 434 435 435 if (fd == -1) { -
uspace/lib/posix/source/unistd.c
r80743a1 rb19e892 335 335 * Check file existence by attempting to open it. 336 336 */ 337 int fd = negerrno(open, path, O_RDONLY); 338 if (fd < 0) { 339 /* errno was set by open() */ 337 int fd = posix_open(path, O_RDONLY); 338 if (fd < 0) 340 339 return -1; 341 }342 340 close(fd); 343 341 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.