summaryrefslogtreecommitdiff
path: root/os2w2
diff options
context:
space:
mode:
Diffstat (limited to 'os2w2')
-rw-r--r--os2w2/.gitignore2
-rw-r--r--os2w2/main.c60
-rw-r--r--os2w2/makefile16
-rw-r--r--os2w2/werkt.pngbin0 -> 29215 bytes
4 files changed, 78 insertions, 0 deletions
diff --git a/os2w2/.gitignore b/os2w2/.gitignore
new file mode 100644
index 0000000..f0c9b81
--- /dev/null
+++ b/os2w2/.gitignore
@@ -0,0 +1,2 @@
+*.o
+main
diff --git a/os2w2/main.c b/os2w2/main.c
new file mode 100644
index 0000000..18108fd
--- /dev/null
+++ b/os2w2/main.c
@@ -0,0 +1,60 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+
+/** @brief stat file to get modified date and print name */
+void print_file(const char* path) {
+ struct stat *info = malloc(sizeof(struct stat));
+ stat(path, info);
+
+ struct tm mtime;
+ localtime_r(&(info->st_mtime), &mtime);
+
+ free(info);
+
+ printf("%04d-%02d-%02d %02d:%02d:%02d %s\n",
+ mtime.tm_year+1900, mtime.tm_mon+1, mtime.tm_mday,
+ mtime.tm_hour, mtime.tm_min, mtime.tm_sec,
+ path);
+}
+
+/** @brief list directory tree recursively */
+void ls_rec(const char *path) {
+ DIR *dir = opendir(path); // get directory handle (used until all content is listed)
+ if (dir == NULL) return; // return early if path is not a directory
+
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != NULL) { // read next file in dir
+ char full_path[1024]; // current entry name with full path prefix
+ snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name); // prepend current directory to current entry
+
+ if (entry->d_type != DT_DIR) {
+ print_file(full_path);
+ continue; // don't try to print files recursively
+ }
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue; // ignore current and parent directory
+
+ print_file(full_path);
+ ls_rec(full_path);
+ }
+
+ closedir(dir); // free directory handle
+}
+
+int main(int argc, const char** argv) {
+ if (argc < 2) {
+ printf("no input directory!\n");
+ return 1;
+ }
+
+ ls_rec(argv[1]);
+
+ return 0;
+}
+
diff --git a/os2w2/makefile b/os2w2/makefile
new file mode 100644
index 0000000..1b726be
--- /dev/null
+++ b/os2w2/makefile
@@ -0,0 +1,16 @@
+CC = gcc
+LD = gcc
+
+CFLAGS += -g
+
+all: main
+
+main: main.o
+ $(LD) $^ $(LFLAGS) -o $@
+
+%.o: %.c
+ $(CC) -c $(CFLAGS) $< -o $@
+
+clean:
+ $(RM) main.o main
+
diff --git a/os2w2/werkt.png b/os2w2/werkt.png
new file mode 100644
index 0000000..fa30636
--- /dev/null
+++ b/os2w2/werkt.png
Binary files differ