diff options
| author | radiohotline <radiohotline@disroot.org> | 2026-03-14 16:20:47 +0300 |
|---|---|---|
| committer | radiohotline <radiohotline@disroot.org> | 2026-03-14 16:20:47 +0300 |
| commit | aad798d9df7417009fa4438aac61ac8e0e4ded36 (patch) | |
| tree | 7729ac68c07e183215687d585203d89e862666e1 /src/touch.c | |
first commit
Diffstat (limited to 'src/touch.c')
| -rw-r--r-- | src/touch.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/touch.c b/src/touch.c new file mode 100644 index 0000000..6cbde27 --- /dev/null +++ b/src/touch.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <sys/time.h> +#include <fcntl.h> +#include <unistd.h> + +#define PROGRAM_NAME "touch" + +int main(int argc, char* argv[]) { + if (argc < 2) { + fprintf(stderr, "%s: missing file operand\n", PROGRAM_NAME); + return 1; + } + + for (int i = 1; i < argc; i++) { + if (utimes(argv[i], NULL) != 0) { + int file = open(argv[i], O_CREAT | O_WRONLY, 0644); + + if (file == -1) { + perror("touch"); + continue; + } + + close(file); + } + } + + return 0; +} |
