summaryrefslogtreecommitdiff
path: root/experiments/watch_file_changes.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-08 06:05:51 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-08 06:05:51 +0200
commit65ffdf410ca5c36f059bee8619f87147f802a82e (patch)
tree047d9b679497a7b5e367e8b1b1f5e5f24d945af2 /experiments/watch_file_changes.c
parent562c07f32366687dcb032b9a2628b9c85a01432e (diff)
downloadttdaw-65ffdf410ca5c36f059bee8619f87147f802a82e.tar.gz
Renamed to experiments and added watch for changes
Diffstat (limited to 'experiments/watch_file_changes.c')
-rw-r--r--experiments/watch_file_changes.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/experiments/watch_file_changes.c b/experiments/watch_file_changes.c
new file mode 100644
index 0000000..04fd3b2
--- /dev/null
+++ b/experiments/watch_file_changes.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <time.h>
+
+int main(void) {
+ struct stat file_stat;
+ time_t last_mod_time;
+ const char* file = "watch_file_changes.txt";
+
+ stat(file, &file_stat);
+ last_mod_time = file_stat.st_mtime;
+
+ while (1) {
+ sleep(1);
+ stat(file, &file_stat);
+ if (file_stat.st_mtime != last_mod_time) {
+ last_mod_time = file_stat.st_mtime;
+
+ struct tm* time_info = localtime(&last_mod_time);
+ char formatted_time[9];
+ strftime(formatted_time, sizeof(formatted_time), "%H:%M:%S", time_info);
+
+ printf("File %s changed at %s\n", file, formatted_time);
+ }
+ }
+ printf("hi\n");
+ return 0;
+}
+