3
0

nuke.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com>
  3. *
  4. * Licensed under GPLv2, see file LICENSE in this source tree.
  5. */
  6. //config:config NUKE
  7. //config: bool "nuke (2.9 kb)"
  8. //config: default y
  9. //config: help
  10. //config: Alias to "rm -rf".
  11. //applet:IF_NUKE(APPLET_NOEXEC(nuke, nuke, BB_DIR_BIN, BB_SUID_DROP, nuke))
  12. //kbuild:lib-$(CONFIG_NUKE) += nuke.o
  13. //usage:#define nuke_trivial_usage
  14. //usage: "DIR..."
  15. //usage:#define nuke_full_usage "\n\n"
  16. //usage: "Remove DIRs"
  17. #include "libbb.h"
  18. /* This is a NOEXEC applet. Be very careful! */
  19. int nuke_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  20. int nuke_main(int argc UNUSED_PARAM, char **argv)
  21. {
  22. // klibc-utils do not check opts, will try to delete "-dir" args
  23. //opt = getopt32(argv, "");
  24. //argv += optind;
  25. while (*++argv) {
  26. #if 0
  27. // klibc-utils do not check this, will happily operate on ".."
  28. const char *base = bb_get_last_path_component_strip(*argv);
  29. if (DOT_OR_DOTDOT(base)) {
  30. bb_error_msg("can't remove '.' or '..'");
  31. continue;
  32. }
  33. #endif
  34. remove_file(*argv, FILEUTILS_FORCE | FILEUTILS_RECUR);
  35. }
  36. // klibc-utils do not indicate errors
  37. return EXIT_SUCCESS;
  38. }