rm.c 674 B

12345678910111213141516171819202122232425262728293031
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2013-2018 K. Lange
  5. *
  6. * rm - Unlink files
  7. *
  8. * TODO: Support recursive, directory removal, etc.
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13. #include <errno.h>
  14. int main(int argc, char * argv[]) {
  15. if (argc < 2) {
  16. fprintf(stderr, "usage: %s FILE...\n", argv[0]);
  17. return 1;
  18. }
  19. int ret = 0;
  20. for (int i = 1; i < argc; ++i) {
  21. if (unlink(argv[i]) < 0) {
  22. fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno));
  23. ret = 1;
  24. }
  25. }
  26. return ret;
  27. }