diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-12-01 21:15:16 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-12-01 21:15:16 (GMT) |
commit | 9b0389d37851ddfe36bb872063218aeaaa4ff383 (patch) | |
tree | da29330a70a9c6ea97a34d356fd710c705a8b8fa /src/common/xdg.c | |
parent | 106e06d33196ca124d6d27cc00a5898d6f96121d (diff) |
Moved the mkpath() function to a proper location.
Diffstat (limited to 'src/common/xdg.c')
-rw-r--r-- | src/common/xdg.c | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/common/xdg.c b/src/common/xdg.c index 29e4cb9..81bc7aa 100644 --- a/src/common/xdg.c +++ b/src/common/xdg.c @@ -27,10 +27,8 @@ #include <dirent.h> #include <glib.h> #include <malloc.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> @@ -105,85 +103,3 @@ char *get_xdg_config_dir(const char *suffix) return result; } - - -/****************************************************************************** -* * -* Paramètres : path = chemin d'accès avec répertoires. * -* * -* Description : S'assure que le chemin fourni est bien en place. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool mkpath(const char *path) -{ - char tmp[PATH_MAX]; /* Recopie de travail */ - size_t len; /* Taille du chemin fourni */ - char *iter; /* Boucle de parcours */ - struct stat info; /* Information sur l'existant */ - int ret; /* Bilan d'un appel système */ - - snprintf(tmp, PATH_MAX, "%s", path); - len = strlen(tmp); - - /* Le chemin fournit ne contient que des répertoires ? */ - if (tmp[len - 1] == G_DIR_SEPARATOR) - tmp[len - 1] = '\0'; - - /* Sinon, on supprime le dernier élément, qui est un fichier */ - else - { - iter = strrchr(tmp, G_DIR_SEPARATOR); - if (iter == NULL) return true; - - *iter = '\0'; - - } - - for(iter = tmp + 1; *iter; iter++) - if(*iter == G_DIR_SEPARATOR) - { - *iter = '\0'; - - /* Analyse de l'existant */ - if (stat(tmp, &info) == 0) - { - if (S_ISDIR(info.st_mode) == 0) - return false; - else - { - *iter = G_DIR_SEPARATOR; - continue; - } - } - - ret = mkdir(tmp, S_IRWXU); - if (ret != 0) - { - perror("mkdir"); - return false; - } - - *iter = G_DIR_SEPARATOR; - - } - - /* Analyse de l'existant */ - if (stat(tmp, &info) == 0) - { - if (S_ISDIR(info.st_mode) == 0) - return false; - else - return true; - } - - ret = mkdir(tmp, S_IRWXU); - if (ret != 0) perror("mkdir"); - - return (ret == 0); - -} |