Changeset 75406dc in mainline for uspace/lib/posix/unistd.c


Ignore:
Timestamp:
2011-07-28T17:39:51Z (14 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:
955c2b0
Parents:
58115ae
Message:

Additional wrappers and fixes for VFS functions.

File:
1 edited

Legend:

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

    r58115ae r75406dc  
    111111        }
    112112        char *ret = getcwd(buf, size);
    113         if (ret == NULL && errno == EOK) {
     113        if (ret == NULL) {
    114114                errno = ERANGE;
    115115        }
    116116        return ret;
     117}
     118
     119/**
     120 * Change the current working directory.
     121 *
     122 * @param path New working directory.
     123 */
     124int posix_chdir(const char *path)
     125{
     126        return errnify(chdir, path);
    117127}
    118128
     
    157167        /* There is currently no support for user accounts in HelenOS. */
    158168        return 0;
     169}
     170
     171/**
     172 * Close a file.
     173 *
     174 * @param fildes
     175 * @return 0 on success, -1 on error.
     176 */
     177int posix_close(int fildes)
     178{
     179        return errnify(close, fildes);
    159180}
    160181
     
    169190ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    170191{
    171         int rc = read(fildes, buf, nbyte);
    172         if (rc < 0) {
    173                 errno = -rc;
    174                 return -1;
    175         } else {
    176                 return rc;
    177         }
     192        return errnify(read, fildes, buf, nbyte);
     193}
     194
     195/**
     196 * Write to a file.
     197 *
     198 * @param fildes File descriptor of the opened file.
     199 * @param buf Buffer to write.
     200 * @param nbyte Size of the buffer.
     201 * @return Number of written bytes on success, -1 otherwise.
     202 */
     203ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
     204{
     205        return errnify(write, fildes, buf, nbyte);
     206}
     207
     208/**
     209 * Requests outstanding data to be written to the underlying storage device.
     210 *
     211 * @param fildes
     212 */
     213int posix_fsync(int fildes)
     214{
     215        return errnify(fsync, fildes);
     216}
     217
     218int posix_ftruncate(int fildes, posix_off_t length)
     219{
     220        return errnify(ftruncate, fildes, (aoff64_t) length);
    178221}
    179222
     
    186229int posix_rmdir(const char *path)
    187230{
    188         int rc = rmdir(path);
    189         if (rc != EOK) {
    190                 errno = -rc;
    191                 return -1;
    192         }
    193         return 0;
     231        return errnify(rmdir, path);
    194232}
    195233
     
    202240int posix_unlink(const char *path)
    203241{
    204         int rc = unlink(path);
    205         if (rc < 0) {
    206                 errno = -rc;
    207                 return -1;
    208         } else {
    209                 return rc;
    210         }
     242        return errnify(unlink, path);
     243}
     244
     245int posix_dup(int fildes)
     246{
     247        return posix_fcntl(fildes, F_DUPFD, 0);
     248}
     249
     250int posix_dup2(int fildes, int fildes2)
     251{
     252        return errnify(dup2, fildes, fildes2);
    211253}
    212254
     
    220262int posix_access(const char *path, int amode)
    221263{
    222         if (amode == F_OK) {
    223                 /* Check file existence by attempt to open it. */
     264        if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) {
     265                /* HelenOS doesn't support permissions, permission checks
     266                 * are equal to existence check.
     267                 *
     268                 * Check file existence by attempting to open it.
     269                 */
    224270                int fd = open(path, O_RDONLY);
    225                 if (fd != -1) {
    226                         close(fd);
     271                if (fd < 0) {
     272                        errno = -fd;
     273                        return 0;
    227274                }
    228                 return fd;
    229         } else if (amode & (X_OK | W_OK | R_OK)) {
    230                 /* HelenOS doesn't support permissions, return success. */
    231                 return 0;
     275                close(fd);
     276                return 1;
    232277        } else {
    233278                /* Invalid amode argument. */
Note: See TracChangeset for help on using the changeset viewer.