diff options
Diffstat (limited to 'myfind/is_newer')
| -rw-r--r-- | myfind/is_newer/Makefile | 15 | ||||
| -rw-r--r-- | myfind/is_newer/is_newer.c | 29 |
2 files changed, 44 insertions, 0 deletions
diff --git a/myfind/is_newer/Makefile b/myfind/is_newer/Makefile new file mode 100644 index 0000000..3787a95 --- /dev/null +++ b/myfind/is_newer/Makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla -D_DEFAULT_SOURCE + +SRC = is_newer.c +OBJ = $(SRC:.c=.o) + +is_newer: $(OBJ) + $(CC) $(OBJ) -o is_newer + +$(OBJ): $(SRC) + +.PHONY: clean + +clean : + $(RM) $(OBJ) is_newer diff --git a/myfind/is_newer/is_newer.c b/myfind/is_newer/is_newer.c new file mode 100644 index 0000000..9f00ffc --- /dev/null +++ b/myfind/is_newer/is_newer.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <sys/stat.h> + +#define _POSIX_C_SOURCE 200809L + +int main(int argc, char **argv) +{ + if (argc != 3) + return 2; + + struct stat f1; + if (stat(argv[1], &f1)) + return 2; + struct stat f2; + if (stat(argv[2], &f2)) + return 2; + + printf("%s is ", argv[1]); + if (f2.st_mtime == f1.st_mtime) + { + if (f2.st_mtim.tv_nsec >= f1.st_mtim.tv_nsec) + printf("not "); + } + else if (f2.st_mtime > f1.st_mtime) + printf("not "); + printf("newer than %s\n", argv[2]); + + return 0; +} |
