summaryrefslogtreecommitdiff
path: root/src/common/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/io.c')
-rw-r--r--src/common/io.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/io.c b/src/common/io.c
index c3d3231..2275cb4 100644
--- a/src/common/io.c
+++ b/src/common/io.c
@@ -24,4 +24,48 @@
#include "io.h"
+#include <libgen.h>
+#include <malloc.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+/******************************************************************************
+* *
+* Paramètres : path = chemin d'accès à valider. *
+* *
+* Description : S'assure qu'un chemin donné existe dans le système. *
+* *
+* Retour : 0 si le chemin est actuellement présent, -1 sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int ensure_path_exists(const char *path)
+{
+ int result; /* Bilan de l'assurance */
+ char *copy; /* Chemin libérable */
+ char *tmp; /* Chemin altérable */
+
+ copy = strdup(path);
+ tmp = dirname(copy);
+
+ result = access(tmp, W_OK | X_OK);
+
+ if (result != 0)
+ {
+ result = ensure_path_exists(tmp);
+
+ if (result == 0)
+ result = mkdir(tmp, 0700);
+
+ }
+
+ free(copy);
+
+ return result;
+
+}