Changeset 1814ee4d in mainline for uspace/lib/posix/unistd.c


Ignore:
Timestamp:
2011-07-29T14:58:39Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e106599
Parents:
d85a01c (diff), 7ae249d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix

File:
1 edited

Legend:

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

    rd85a01c r1814ee4d  
    110110                return NULL;
    111111        }
     112       
     113        /* Save the original value to comply with the "no modification on
     114         * success" semantics.
     115         */
     116        int orig_errno = errno;
     117        errno = EOK;
     118       
    112119        char *ret = getcwd(buf, size);
    113         if (ret == NULL && errno == EOK) {
    114                 errno = ERANGE;
    115         }
     120        if (ret == NULL) {
     121                /* Check errno to avoid shadowing other possible errors. */
     122                if (errno == EOK) {
     123                        errno = ERANGE;
     124                }
     125        } else {
     126                /* Success, restore previous errno value. */
     127                errno = orig_errno;
     128        }
     129       
    116130        return ret;
     131}
     132
     133/**
     134 * Change the current working directory.
     135 *
     136 * @param path New working directory.
     137 */
     138int posix_chdir(const char *path)
     139{
     140        return errnify(chdir, path);
    117141}
    118142
     
    157181        /* There is currently no support for user accounts in HelenOS. */
    158182        return 0;
     183}
     184
     185/**
     186 * Close a file.
     187 *
     188 * @param fildes
     189 * @return 0 on success, -1 on error.
     190 */
     191int posix_close(int fildes)
     192{
     193        return errnify(close, fildes);
    159194}
    160195
     
    169204ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    170205{
    171         int rc = read(fildes, buf, nbyte);
    172         if (rc < 0) {
    173                 errno = -rc;
    174                 return -1;
    175         } else {
    176                 return rc;
    177         }
     206        return errnify(read, fildes, buf, nbyte);
     207}
     208
     209/**
     210 * Write to a file.
     211 *
     212 * @param fildes File descriptor of the opened file.
     213 * @param buf Buffer to write.
     214 * @param nbyte Size of the buffer.
     215 * @return Number of written bytes on success, -1 otherwise.
     216 */
     217ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
     218{
     219        return errnify(write, fildes, buf, nbyte);
     220}
     221
     222/**
     223 * Requests outstanding data to be written to the underlying storage device.
     224 *
     225 * @param fildes
     226 */
     227int posix_fsync(int fildes)
     228{
     229        return errnify(fsync, fildes);
     230}
     231
     232int posix_ftruncate(int fildes, posix_off_t length)
     233{
     234        return errnify(ftruncate, fildes, (aoff64_t) length);
     235}
     236
     237/**
     238 * Remove a directory.
     239 *
     240 * @param path Directory pathname.
     241 * @return Zero on success, -1 otherwise.
     242 */
     243int posix_rmdir(const char *path)
     244{
     245        return errnify(rmdir, path);
    178246}
    179247
     
    186254int posix_unlink(const char *path)
    187255{
    188         int rc = unlink(path);
    189         if (rc < 0) {
    190                 errno = -rc;
    191                 return -1;
    192         } else {
    193                 return rc;
    194         }
     256        return errnify(unlink, path);
     257}
     258
     259int posix_dup(int fildes)
     260{
     261        return posix_fcntl(fildes, F_DUPFD, 0);
     262}
     263
     264int posix_dup2(int fildes, int fildes2)
     265{
     266        return errnify(dup2, fildes, fildes2);
    195267}
    196268
     
    204276int posix_access(const char *path, int amode)
    205277{
    206         if (amode == F_OK) {
    207                 /* Check file existence by attempt to open it. */
     278        if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) {
     279                /* HelenOS doesn't support permissions, permission checks
     280                 * are equal to existence check.
     281                 *
     282                 * Check file existence by attempting to open it.
     283                 */
    208284                int fd = open(path, O_RDONLY);
    209                 if (fd != -1) {
    210                         close(fd);
     285                if (fd < 0) {
     286                        errno = -fd;
     287                        return -1;
    211288                }
    212                 return fd;
    213         } else if (amode & (X_OK | W_OK | R_OK)) {
    214                 /* HelenOS doesn't support permissions, return success. */
     289                close(fd);
    215290                return 0;
    216291        } else {
Note: See TracChangeset for help on using the changeset viewer.