diff --git a/src/chat/config.c b/src/chat/config.c index 243b435..a4722e1 100644 --- a/src/chat/config.c +++ b/src/chat/config.c @@ -39,17 +39,11 @@ enum CONFIG_TYPES void init_config(char *filename) { - struct stat st; - char *buffer = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER")); - //CREATE USER CONFIG FOLDER [THIS SHOULDN'T HAPPEN ON CLIENT, BUT IT'S NEEDED ON FRESH SERVERS] - if (stat(buffer, &st) == -1) - { - mkdir(buffer, 0700); - } + why2_directory(); //GET THE CONFIG TYPE - buffer = why2_realloc(buffer, strlen(WHY2_CHAT_CONFIG_DIR) + strlen(filename) + 2); + char *buffer = why2_malloc(strlen(WHY2_CHAT_CONFIG_DIR) + strlen(filename) + 2); sprintf(buffer, "%s/%s", WHY2_CHAT_CONFIG_DIR, filename); char *path = why2_replace(buffer, "{USER}", getenv("USER")); diff --git a/src/core/lib/utils/misc.c b/src/core/lib/utils/misc.c index 3ce8873..e28c8a2 100644 --- a/src/core/lib/utils/misc.c +++ b/src/core/lib/utils/misc.c @@ -52,6 +52,21 @@ int removeDirectory(char *path) return nftw(path, unlink_cb, 64, FTW_DEPTH | FTW_PHYS); } +void why2_directory(void) +{ + struct stat st; + char *buffer = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER")); + + //CREATE USER CONFIG FOLDER + if (stat(buffer, &st) == -1) + { + mkdir(buffer, 0700); + } + + //DEALLOCATION + why2_deallocate(buffer); +} + enum WHY2_EXIT_CODES why2_check_version(void) { if (why2_get_flags().no_check) return WHY2_SUCCESS;