3
0

rm.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. /* BB_AUDIT SUSv3 compliant */
  24. /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
  25. /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
  26. *
  27. * Size reduction.
  28. */
  29. #include <unistd.h>
  30. #include "busybox.h"
  31. extern int rm_main(int argc, char **argv)
  32. {
  33. int status = 0;
  34. int flags = 0;
  35. unsigned long opt;
  36. bb_opt_complementaly = "f-i:i-f";
  37. opt = bb_getopt_ulflags(argc, argv, "fiRr");
  38. if(opt & 1)
  39. flags |= FILEUTILS_FORCE;
  40. if(opt & 2)
  41. flags |= FILEUTILS_INTERACTIVE;
  42. if(opt & 12)
  43. flags |= FILEUTILS_RECUR;
  44. if (*(argv += optind) != NULL) {
  45. do {
  46. const char *base = bb_get_last_path_component(*argv);
  47. if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) {
  48. bb_error_msg("cannot remove `.' or `..'");
  49. } else if (remove_file(*argv, flags) >= 0) {
  50. continue;
  51. }
  52. status = 1;
  53. } while (*++argv);
  54. } else if (!(flags & FILEUTILS_FORCE)) {
  55. bb_show_usage();
  56. }
  57. return status;
  58. }