diff options
Diffstat (limited to '')
-rw-r--r-- | touch.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -1,12 +1,39 @@ #include <stdio.h> +#include <utime.h> +#include <unistd.h> +#include <string.h> int main(int argc, char *argv[]) { FILE *f; + int wr = 1; + int v = 0; + int c; + + while ((c = getopt(argc, argv, "cv")) != -1) { + switch (c) { + case 'c': wr = 0; break; + case 'v': v = 1; break; + } + } for (int i = 1; i < argc; i++) { - f = fopen(argv[i], "a"); - fprintf(f, "\n"); /* TODO make this actually work without writing anything to the file*/ - fclose(f); + while (strncmp(argv[i], "-", 1) == 0) /* ignore args that start with - */ + i++; + if (wr) { + if (access (argv[i], F_OK) && v) { + printf("Making new file '%s'.\n", argv[i]); + } else if (v) { + printf("File '%s' already exists, updating time.\n", argv[i]); + } + f = fopen(argv[i], "w"); + fclose(f); + } + if (access (argv[i], F_OK) && !wr && v) { + printf("File '%s' doesn't exist, Can't update time.\n", argv[i]); + } else if (!wr && v) { + printf("File '%s' exist's, updating time.\n", argv[i]); + } + utime(argv[i], NULL); } } |