Ignore:
File:
1 edited

Legend:

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

    r6afc9d7 r820104d  
    105105char *posix_getcwd(char *buf, size_t size)
    106106{
    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;
    111113                return NULL;
    112114        }
    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;
    115134}
    116135
     
    122141int posix_chdir(const char *path)
    123142{
    124         return negerrno(chdir, path);
     143        return errnify(chdir, path);
    125144}
    126145
     
    175194int posix_close(int fildes)
    176195{
    177         return negerrno(close, fildes);
     196        return errnify(close, fildes);
    178197}
    179198
     
    188207ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    189208{
    190         return negerrno(read, fildes, buf, nbyte);
     209        return errnify(read, fildes, buf, nbyte);
    191210}
    192211
     
    201220ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
    202221{
    203         return negerrno(write, fildes, buf, nbyte);
     222        return errnify(write, fildes, buf, nbyte);
    204223}
    205224
     
    215234posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
    216235{
    217         return negerrno(lseek, fildes, offset, whence);
     236        return errnify(lseek, fildes, offset, whence);
    218237}
    219238
     
    226245int posix_fsync(int fildes)
    227246{
    228         return negerrno(fsync, fildes);
     247        return errnify(fsync, fildes);
    229248}
    230249
     
    238257int posix_ftruncate(int fildes, posix_off_t length)
    239258{
    240         return negerrno(ftruncate, fildes, (aoff64_t) length);
     259        return errnify(ftruncate, fildes, (aoff64_t) length);
    241260}
    242261
     
    249268int posix_rmdir(const char *path)
    250269{
    251         return negerrno(rmdir, path);
     270        return errnify(rmdir, path);
    252271}
    253272
     
    260279int posix_unlink(const char *path)
    261280{
    262         return negerrno(unlink, path);
     281        return errnify(unlink, path);
    263282}
    264283
     
    284303int posix_dup2(int fildes, int fildes2)
    285304{
    286         return negerrno(dup2, fildes, fildes2);
     305        return errnify(dup2, fildes, fildes2);
    287306}
    288307
     
    302321                 * Check file existence by attempting to open it.
    303322                 */
    304                 int fd = negerrno(open, path, O_RDONLY);
     323                int fd = open(path, O_RDONLY);
    305324                if (fd < 0) {
    306                         /* errno was set by open() */
     325                        errno = -fd;
    307326                        return -1;
    308327                }
Note: See TracChangeset for help on using the changeset viewer.