Changes in uspace/lib/posix/source/unistd.c [820104d:6afc9d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/unistd.c
r820104d r6afc9d7 105 105 char *posix_getcwd(char *buf, size_t size) 106 106 { 107 /* Native getcwd() does not set any errno despite the fact that general 108 * usage pattern of this function depends on it (caller is repeatedly 109 * guessing the required size of the buffer by checking for ERANGE on 110 * failure). */ 111 if (size == 0) { 112 errno = EINVAL; 107 char *p = getcwd(buf, size); 108 109 if (p == NULL) { 110 errno = -errno; 113 111 return NULL; 114 112 } 115 116 /* Save the original value to comply with the "no modification on 117 * success" semantics. 118 */ 119 int orig_errno = errno; 120 errno = EOK; 121 122 char *ret = getcwd(buf, size); 123 if (ret == NULL) { 124 /* Check errno to avoid shadowing other possible errors. */ 125 if (errno == EOK) { 126 errno = ERANGE; 127 } 128 } else { 129 /* Success, restore previous errno value. */ 130 errno = orig_errno; 131 } 132 133 return ret; 113 114 return p; 134 115 } 135 116 … … 141 122 int posix_chdir(const char *path) 142 123 { 143 return errnify(chdir, path);124 return negerrno(chdir, path); 144 125 } 145 126 … … 194 175 int posix_close(int fildes) 195 176 { 196 return errnify(close, fildes);177 return negerrno(close, fildes); 197 178 } 198 179 … … 207 188 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 208 189 { 209 return errnify(read, fildes, buf, nbyte);190 return negerrno(read, fildes, buf, nbyte); 210 191 } 211 192 … … 220 201 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 221 202 { 222 return errnify(write, fildes, buf, nbyte);203 return negerrno(write, fildes, buf, nbyte); 223 204 } 224 205 … … 234 215 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence) 235 216 { 236 return errnify(lseek, fildes, offset, whence);217 return negerrno(lseek, fildes, offset, whence); 237 218 } 238 219 … … 245 226 int posix_fsync(int fildes) 246 227 { 247 return errnify(fsync, fildes);228 return negerrno(fsync, fildes); 248 229 } 249 230 … … 257 238 int posix_ftruncate(int fildes, posix_off_t length) 258 239 { 259 return errnify(ftruncate, fildes, (aoff64_t) length);240 return negerrno(ftruncate, fildes, (aoff64_t) length); 260 241 } 261 242 … … 268 249 int posix_rmdir(const char *path) 269 250 { 270 return errnify(rmdir, path);251 return negerrno(rmdir, path); 271 252 } 272 253 … … 279 260 int posix_unlink(const char *path) 280 261 { 281 return errnify(unlink, path);262 return negerrno(unlink, path); 282 263 } 283 264 … … 303 284 int posix_dup2(int fildes, int fildes2) 304 285 { 305 return errnify(dup2, fildes, fildes2);286 return negerrno(dup2, fildes, fildes2); 306 287 } 307 288 … … 321 302 * Check file existence by attempting to open it. 322 303 */ 323 int fd = open(path, O_RDONLY);304 int fd = negerrno(open, path, O_RDONLY); 324 305 if (fd < 0) { 325 errno = -fd;306 /* errno was set by open() */ 326 307 return -1; 327 308 }
Note:
See TracChangeset
for help on using the changeset viewer.