Changeset 58115ae in mainline


Ignore:
Timestamp:
2011-07-27T23:05:15Z (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:
75406dc
Parents:
fd4b636
Message:

Make remove() future-proof and add rmdir() wrapper.

Location:
uspace/lib/posix
Files:
3 edited

Legend:

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

    rfd4b636 r58115ae  
    693693
    694694/**
    695  * Remove a file.
     695 * Remove a file or directory.
    696696 *
    697697 * @param path Pathname of the file that shall be removed.
    698  * @return Zero on success, -1 otherwise.
     698 * @return Zero on success, -1 (with errno set) otherwise.
    699699 */
    700700int posix_remove(const char *path)
    701701{
    702         // FIXME: unlink() and rmdir() seem to be equivalent at the moment,
    703         //        but that does not have to be true forever
    704         return unlink(path);
     702        struct stat st;
     703        int rc = stat(path, &st);
     704       
     705        if (rc != EOK) {
     706                errno = -rc;
     707                return -1;
     708        }
     709       
     710        if (st.is_directory) {
     711                rc = rmdir(path);
     712        } else {
     713                rc = unlink(path);
     714        }
     715       
     716        if (rc != EOK) {
     717                errno = -rc;
     718                return -1;
     719        }
     720        return 0;
    705721}
    706722
  • uspace/lib/posix/unistd.c

    rfd4b636 r58115ae  
    176176                return rc;
    177177        }
     178}
     179
     180/**
     181 * Remove a directory.
     182 *
     183 * @param path Directory pathname.
     184 * @return Zero on success, -1 otherwise.
     185 */
     186int posix_rmdir(const char *path)
     187{
     188        int rc = rmdir(path);
     189        if (rc != EOK) {
     190                errno = -rc;
     191                return -1;
     192        }
     193        return 0;
    178194}
    179195
  • uspace/lib/posix/unistd.h

    rfd4b636 r58115ae  
    7373
    7474/* Deleting Files */
     75extern int posix_rmdir(const char *path);
    7576extern int posix_unlink(const char *path);
    7677
     
    156157        #define read posix_read
    157158
     159        #define rmdir posix_rmdir
    158160        #define unlink posix_unlink
    159161
Note: See TracChangeset for help on using the changeset viewer.