summaryrefslogtreecommitdiffstats
path: root/bio/vaje/1/programi/fopenmkdir.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-11-14 00:00:59 +0100
committersijanec <sijanecantonluka@gmail.com>2020-11-14 00:00:59 +0100
commitba067958e13d2bdb3fa95644771ee40ac13c4db2 (patch)
treee3cb1bd108d544c1f650e415fdfcad15a524ea0c /bio/vaje/1/programi/fopenmkdir.c
parentnemščina delo 12. 11 (diff)
downloadsola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.gz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.bz2
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.lz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.xz
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.tar.zst
sola-gimb-2-ba067958e13d2bdb3fa95644771ee40ac13c4db2.zip
Diffstat (limited to 'bio/vaje/1/programi/fopenmkdir.c')
-rw-r--r--bio/vaje/1/programi/fopenmkdir.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/bio/vaje/1/programi/fopenmkdir.c b/bio/vaje/1/programi/fopenmkdir.c
new file mode 100644
index 0000000..afca4f1
--- /dev/null
+++ b/bio/vaje/1/programi/fopenmkdir.c
@@ -0,0 +1,34 @@
+#pragma once
+#include <mkdirp.c>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+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[PATH_MAX];
+ 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;
+ }
+}