Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/unistd.c

    r5759642f r6afc9d7  
    105105char *posix_getcwd(char *buf, size_t size)
    106106{
    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;
    113111                return NULL;
    114112        }
    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;
    134115}
    135116
     
    141122int posix_chdir(const char *path)
    142123{
    143         return errnify(chdir, path);
     124        return negerrno(chdir, path);
    144125}
    145126
     
    194175int posix_close(int fildes)
    195176{
    196         return errnify(close, fildes);
     177        return negerrno(close, fildes);
    197178}
    198179
     
    207188ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    208189{
    209         return errnify(read, fildes, buf, nbyte);
     190        return negerrno(read, fildes, buf, nbyte);
    210191}
    211192
     
    220201ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
    221202{
    222         return errnify(write, fildes, buf, nbyte);
     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 */
     215posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
     216{
     217        return negerrno(lseek, fildes, offset, whence);
    223218}
    224219
     
    231226int posix_fsync(int fildes)
    232227{
    233         return errnify(fsync, fildes);
     228        return negerrno(fsync, fildes);
    234229}
    235230
     
    243238int posix_ftruncate(int fildes, posix_off_t length)
    244239{
    245         return errnify(ftruncate, fildes, (aoff64_t) length);
     240        return negerrno(ftruncate, fildes, (aoff64_t) length);
    246241}
    247242
     
    254249int posix_rmdir(const char *path)
    255250{
    256         return errnify(rmdir, path);
     251        return negerrno(rmdir, path);
    257252}
    258253
     
    265260int posix_unlink(const char *path)
    266261{
    267         return errnify(unlink, path);
     262        return negerrno(unlink, path);
    268263}
    269264
     
    289284int posix_dup2(int fildes, int fildes2)
    290285{
    291         return errnify(dup2, fildes, fildes2);
     286        return negerrno(dup2, fildes, fildes2);
    292287}
    293288
     
    307302                 * Check file existence by attempting to open it.
    308303                 */
    309                 int fd = open(path, O_RDONLY);
     304                int fd = negerrno(open, path, O_RDONLY);
    310305                if (fd < 0) {
    311                         errno = -fd;
     306                        /* errno was set by open() */
    312307                        return -1;
    313308                }
     
    375370        // TODO: low priority, just a compile-time dependency of binutils
    376371        not_implemented();
     372        return -1;
    377373}
    378374
     
    385381        // TODO: low priority, just a compile-time dependency of binutils
    386382        not_implemented();
     383        return -1;
    387384}
    388385
     
    397394        // TODO: low priority, just a compile-time dependency of binutils
    398395        not_implemented();
     396        return -1;
    399397}
    400398
     
    409407        // TODO: low priority, just a compile-time dependency of binutils
    410408        not_implemented();
     409        return -1;
    411410}
    412411
     
    420419        // TODO: low priority, just a compile-time dependency of binutils
    421420        not_implemented();
     421        return -1;
    422422}
    423423
Note: See TracChangeset for help on using the changeset viewer.