touch.c 653 B

123456789101112131415161718192021222324252627282930
  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 K. Lange
  5. *
  6. * touch - Create or update file timestamps
  7. *
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <errno.h>
  12. int main(int argc, char * argv[]) {
  13. if (argc < 2) {
  14. fprintf(stderr, "%s: argument expected\n", argv[0]);
  15. return 1;
  16. }
  17. int out = 0;
  18. for (int i = 1; i < argc; ++i) {
  19. FILE * f = fopen(argv[i], "a");
  20. if (!f) {
  21. fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno));
  22. out = 1;
  23. }
  24. fclose(f);
  25. }
  26. return out;
  27. }