From 52a5a9d9bd8d767bd76c02f20668e1c7d92e33f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Wed, 29 Apr 2020 22:38:41 +0200 Subject: setting up folder structure --- src/fopenmkdir.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/fopenmkdir.c (limited to 'src/fopenmkdir.c') diff --git a/src/fopenmkdir.c b/src/fopenmkdir.c new file mode 100644 index 0000000..e4c4d68 --- /dev/null +++ b/src/fopenmkdir.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +FILE * fopen_mkdir(char* filename, char* mode) { + FILE * file_to_return; + file_to_return = fopen(filename, mode); + if(file_to_return == NULL) { + char folder_of_file[256]; + strcpy(folder_of_file, filename); + char * p; + p = strrchr(folder_of_file, '/'); + if (!p) { + printf("[fopenmkdir.c] filename contains no slash.\n"); + return NULL; + } else { + printf("folder is %s\n", folder_of_file); + printf("filename is %s\n", filename); + *p = '\0'; + } + if(mkdir_p(folder_of_file) != 0) { + return NULL; + } + file_to_return = fopen(filename, mode); + if(file_to_return == NULL) { + return NULL; + } + return file_to_return; + } else { + return file_to_return; + } +} -- cgit v1.2.3