remove.c 802 B

123456789101112131415161718192021222324252627282930313233
  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. #define rmdir __rmdir
  8. #define unlink __unlink
  9. #include "_stdio.h"
  10. #include <unistd.h>
  11. #include <errno.h>
  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. int attribute_hidden __remove(register const char *filename)
  18. {
  19. int saved_errno = errno;
  20. int rv;
  21. if (((rv = rmdir(filename)) < 0) && (errno == ENOTDIR)) {
  22. __set_errno(saved_errno); /* Need to restore errno. */
  23. rv = unlink(filename);
  24. }
  25. return rv;
  26. }
  27. strong_alias(__remove,remove)