Changes in uspace/lib/posix/source/unistd.c [6afc9d7:5759642f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/unistd.c
r6afc9d7 r5759642f 105 105 char *posix_getcwd(char *buf, size_t size) 106 106 { 107 char *p = getcwd(buf, size); 108 109 if (p == NULL) { 110 errno = -errno; 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; 111 113 return NULL; 112 114 } 113 114 return p; 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; 115 134 } 116 135 … … 122 141 int posix_chdir(const char *path) 123 142 { 124 return negerrno(chdir, path);143 return errnify(chdir, path); 125 144 } 126 145 … … 175 194 int posix_close(int fildes) 176 195 { 177 return negerrno(close, fildes);196 return errnify(close, fildes); 178 197 } 179 198 … … 188 207 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 189 208 { 190 return negerrno(read, fildes, buf, nbyte);209 return errnify(read, fildes, buf, nbyte); 191 210 } 192 211 … … 201 220 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 202 221 { 203 return negerrno(write, fildes, buf, nbyte); 204 } 205 206 /** 207 * Reposition read/write file offset 208 * 209 * @param fildes File descriptor of the opened file. 210 * @param offset New offset in the file. 211 * @param whence The position from which the offset argument is specified. 212 * @return Upon successful completion, returns the resulting offset 213 * as measured in bytes from the beginning of the file, -1 otherwise. 214 */ 215 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence) 216 { 217 return negerrno(lseek, fildes, offset, whence); 222 return errnify(write, fildes, buf, nbyte); 218 223 } 219 224 … … 226 231 int posix_fsync(int fildes) 227 232 { 228 return negerrno(fsync, fildes);233 return errnify(fsync, fildes); 229 234 } 230 235 … … 238 243 int posix_ftruncate(int fildes, posix_off_t length) 239 244 { 240 return negerrno(ftruncate, fildes, (aoff64_t) length);245 return errnify(ftruncate, fildes, (aoff64_t) length); 241 246 } 242 247 … … 249 254 int posix_rmdir(const char *path) 250 255 { 251 return negerrno(rmdir, path);256 return errnify(rmdir, path); 252 257 } 253 258 … … 260 265 int posix_unlink(const char *path) 261 266 { 262 return negerrno(unlink, path);267 return errnify(unlink, path); 263 268 } 264 269 … … 284 289 int posix_dup2(int fildes, int fildes2) 285 290 { 286 return negerrno(dup2, fildes, fildes2);291 return errnify(dup2, fildes, fildes2); 287 292 } 288 293 … … 302 307 * Check file existence by attempting to open it. 303 308 */ 304 int fd = negerrno(open,path, O_RDONLY);309 int fd = open(path, O_RDONLY); 305 310 if (fd < 0) { 306 /* errno was set by open() */311 errno = -fd; 307 312 return -1; 308 313 } … … 370 375 // TODO: low priority, just a compile-time dependency of binutils 371 376 not_implemented(); 372 return -1;373 377 } 374 378 … … 381 385 // TODO: low priority, just a compile-time dependency of binutils 382 386 not_implemented(); 383 return -1;384 387 } 385 388 … … 394 397 // TODO: low priority, just a compile-time dependency of binutils 395 398 not_implemented(); 396 return -1;397 399 } 398 400 … … 407 409 // TODO: low priority, just a compile-time dependency of binutils 408 410 not_implemented(); 409 return -1;410 411 } 411 412 … … 419 420 // TODO: low priority, just a compile-time dependency of binutils 420 421 not_implemented(); 421 return -1;422 422 } 423 423
Note:
See TracChangeset
for help on using the changeset viewer.