3
0

rm.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "libbb.h"
  16. /* This is a NOFORK applet. Be very careful! */
  17. int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  18. int rm_main(int argc ATTRIBUTE_UNUSED, char **argv)
  19. {
  20. int status = 0;
  21. int flags = 0;
  22. unsigned opt;
  23. opt_complementary = "f-i:i-f";
  24. opt = getopt32(argv, "fiRr");
  25. argv += optind;
  26. if (opt & 1)
  27. flags |= FILEUTILS_FORCE;
  28. if (opt & 2)
  29. flags |= FILEUTILS_INTERACTIVE;
  30. if (opt & 12)
  31. flags |= FILEUTILS_RECUR;
  32. if (*argv != NULL) {
  33. do {
  34. const char *base = bb_get_last_path_component_strip(*argv);
  35. if (DOT_OR_DOTDOT(base)) {
  36. bb_error_msg("cannot remove '.' or '..'");
  37. } else if (remove_file(*argv, flags) >= 0) {
  38. continue;
  39. }
  40. status = 1;
  41. } while (*++argv);
  42. } else if (!(flags & FILEUTILS_FORCE)) {
  43. bb_show_usage();
  44. }
  45. return status;
  46. }