remove.c 732 B

12345678910111213141516171819202122232425262728293031
  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. rv = rmdir(filename);
  20. if ((rv < 0) && (errno == ENOTDIR)) {
  21. __set_errno(saved_errno); /* Need to restore errno. */
  22. rv = unlink(filename);
  23. }
  24. return rv;
  25. }
  26. libc_hidden_def(remove)