remove.c 706 B

1234567891011121314151617181920212223242526272829
  1. /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * GNU Library General Public License (LGPL) version 2 or later.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #include "_stdio.h"
  8. #include <unistd.h>
  9. #include <errno.h>
  10. /* SUSv3 states:
  11. * If path does not name a directory, remove(path) shall be equivalent
  12. * to unlink(path). If path names a directory, remove(path) shall be
  13. * equivalent to rmdir(path).
  14. */
  15. int remove(register const char *filename)
  16. {
  17. int saved_errno = errno;
  18. int rv;
  19. if (((rv = rmdir(filename)) < 0) && (errno == ENOTDIR)) {
  20. __set_errno(saved_errno); /* Need to restore errno. */
  21. rv = unlink(filename);
  22. }
  23. return rv;
  24. }