remove.c 808 B

12345678910111213141516171819202122232425262728293031323334
  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. libc_hidden_proto(rmdir)
  11. libc_hidden_proto(unlink)
  12. /* SUSv3 states:
  13. * If path does not name a directory, remove(path) shall be equivalent
  14. * to unlink(path). If path names a directory, remove(path) shall be
  15. * equivalent to rmdir(path).
  16. */
  17. libc_hidden_proto(remove)
  18. int remove(register const char *filename)
  19. {
  20. int saved_errno = errno;
  21. int rv;
  22. if (((rv = rmdir(filename)) < 0) && (errno == ENOTDIR)) {
  23. __set_errno(saved_errno); /* Need to restore errno. */
  24. rv = unlink(filename);
  25. }
  26. return rv;
  27. }
  28. libc_hidden_def(remove)