logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://hacktivis.me/git/bootstrap-initrd.git

mv-stub.c (788B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #include <stdio.h> // fprintf, rename
  5. #include <unistd.h> // getopt
  6. #include <string.h> // strerror
  7. #include <errno.h>
  8. int
  9. main(int argc, char *argv[])
  10. {
  11. int c = -1;
  12. while((c = getopt(argc, argv, ":f")) != -1)
  13. {
  14. switch(c)
  15. {
  16. case 'f':
  17. // ignored
  18. break;
  19. case '?':
  20. fprintf(stderr, "mv: Unknown option '-%c'\n", optopt);
  21. break;
  22. }
  23. }
  24. argc -= optind;
  25. argv += optind;
  26. if(argc != 2)
  27. {
  28. fprintf(stderr, "Usage: mv [-f] src dest\n");
  29. return 1;
  30. }
  31. if(rename(argv[0], argv[1]) != 0)
  32. {
  33. fprintf(stderr, "mv: Failed renaming: %s\n", strerror(errno));
  34. return 1;
  35. }
  36. return 0;
  37. }