From 52893085451b91486c6ce36e5087a27bd0618c97 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Jan 2023 00:03:46 +0100 Subject: [PATCH] missing a bracket --- client/src/ui.c | 128 +++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/client/src/ui.c b/client/src/ui.c index 00eb8d022..ff885af37 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -23,7 +23,6 @@ #endif #include "ui.h" #include "commonutil.h" // ARRAYLEN - #include // for Mingw readline #include #include @@ -62,10 +61,18 @@ pthread_mutex_t g_print_lock = PTHREAD_MUTEX_INITIALIZER; static void fPrintAndLog(FILE *stream, const char *fmt, ...); +#ifdef _WIN32 + #define MKDIR_CHK _mkdir(path) +#else + #define MKDIR_CHK mkdir(path, 0700) +#endif + + // needed by flasher, so let's put it here instead of fileutils.c int searchHomeFilePath(char **foundpath, const char *subdir, const char *filename, bool create_home) { - if (foundpath == NULL) + if (foundpath == NULL) { return PM3_EINVARG; + } const char *user_path = get_my_user_directory(); if (user_path == NULL) { @@ -75,93 +82,92 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam size_t pathlen = strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1; char *path = calloc(pathlen, sizeof(char)); - if (path == NULL) + if (path == NULL) { return PM3_EMALLOC; + } strcpy(path, user_path); strcat(path, PM3_USER_DIRECTORY); int result; + #ifdef _WIN32 struct _stat st; // Mingw _stat fails if path ends with /, so let's use a stripped path - if (str_endswith(path, PATHSEP)) - - memset(path + (strlen(path) - strlen(PATHSEP)), 0x00, strlen(PATHSEP)); - result = _stat(path, &st); - strncat(path, PATHSEP, strlen(PATHSEP)); -} else { - result = _stat(path, &st); -} -#else - struct stat st; - result = stat(path, &st); -#endif -if ((result != 0) && create_home) { - -#ifdef _WIN32 - if (_mkdir(path)) -#else - if (mkdir(path, 0700)) -#endif - { - fprintf(stderr, "Could not create user directory %s\n", path); - free(path); - return PM3_EFILE; - } -} -if (subdir != NULL) { - pathlen += strlen(subdir); - char *tmp = realloc(path, pathlen * sizeof(char)); - if (tmp == NULL) { - //free(path); - return PM3_EMALLOC; - } - path = tmp; - strcat(path, subdir); - -#ifdef _WIN32 - // Mingw _stat fails if path ends with /, so let's use a stripped path - if (path[strlen(path) - 1] == '/') { - path[strlen(path) - 1] = '\0'; + if (str_endswith(path, PATHSEP)) { + memset(path + (strlen(path) - strlen(PATHSEP)), 0x00, strlen(PATHSEP)); result = _stat(path, &st); - path[strlen(path)] = '/'; + strncat(path, PATHSEP, strlen(PATHSEP)); } else { result = _stat(path, &st); } #else + struct stat st; result = stat(path, &st); #endif + if ((result != 0) && create_home) { -#ifdef _WIN32 - if (_mkdir(path)) -#else - if (mkdir(path, 0700)) -#endif + if (MKDIR_CHK) { fprintf(stderr, "Could not create user directory %s\n", path); free(path); return PM3_EFILE; } } -} -if (filename == NULL) { + if (subdir != NULL) { + pathlen += strlen(subdir); + char *tmp = realloc(path, pathlen * sizeof(char)); + if (tmp == NULL) { + //free(path); + return PM3_EMALLOC; + } + path = tmp; + strcat(path, subdir); + +#ifdef _WIN32 + // Mingw _stat fails if path ends with /, so let's use a stripped path + if (str_endswith(path, PATHSEP)) { + memset(path + (strlen(path) - strlen(PATHSEP)), 0x00, strlen(PATHSEP)); + result = _stat(path, &st); + strncat(path, PATHSEP, strlen(PATHSEP)); + } else { + result = _stat(path, &st); + } +#else + result = stat(path, &st); +#endif + + if ((result != 0) && create_home) { + + if (MKDIR_CHK) + { + fprintf(stderr, "Could not create user directory %s\n", path); + free(path); + return PM3_EFILE; + } + } + } + + if (filename == NULL) { + *foundpath = path; + return PM3_SUCCESS; + } + + pathlen += strlen(filename); + char *tmp = realloc(path, pathlen *sizeof(char)); + if (tmp == NULL) { + //free(path); + return PM3_EMALLOC; + } + + path = tmp; + strcat(path, filename); *foundpath = path; + return PM3_SUCCESS; } -pathlen += strlen(filename); -char *tmp = realloc(path, pathlen *sizeof(char)); -if (tmp == NULL) { - //free(path); - return PM3_EMALLOC; -} -path = tmp; -strcat(path, filename); -*foundpath = path; -return PM3_SUCCESS; -} void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) { char buff[2000] = "Options:\n";