diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2014-07-10 14:47:37 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2014-07-10 14:47:37 (GMT) | 
| commit | db863244b804cbf4c06399f7c6f8241d91c9ee9b (patch) | |
| tree | da7cc911b0f10c5122536271235ab68f2202804a /src/common/io.c | |
| parent | e8aa314462196cc9e8461ae23eb13f8bffcc983f (diff) | |
Fully rewritten the core configuration system.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@381 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common/io.c')
| -rw-r--r-- | src/common/io.c | 44 | 
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; + +} | 
