rm.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini rm implementation for busybox
  4. *
  5. * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. /* BB_AUDIT SUSv3 compliant */
  10. /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
  11. /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
  12. *
  13. * Size reduction.
  14. */
  15. #include <unistd.h>
  16. #include "busybox.h"
  17. int rm_main(int argc, char **argv)
  18. {
  19. int status = 0;
  20. int flags = 0;
  21. unsigned opt;
  22. opt_complementary = "f-i:i-f";
  23. opt = getopt32(argc, argv, "fiRr");
  24. if(opt & 1)
  25. flags |= FILEUTILS_FORCE;
  26. if(opt & 2)
  27. flags |= FILEUTILS_INTERACTIVE;
  28. if(opt & 12)
  29. flags |= FILEUTILS_RECUR;
  30. if (*(argv += optind) != NULL) {
  31. do {
  32. const char *base = bb_get_last_path_component(*argv);
  33. if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) {
  34. bb_error_msg("cannot remove '.' or '..'");
  35. } else if (remove_file(*argv, flags) >= 0) {
  36. continue;
  37. }
  38. status = 1;
  39. } while (*++argv);
  40. } else if (!(flags & FILEUTILS_FORCE)) {
  41. bb_show_usage();
  42. }
  43. return status;
  44. }