mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
adapt file path checks
This commit is contained in:
parent
d1aa57ac5d
commit
19dd580b3b
1 changed files with 50 additions and 49 deletions
|
@ -85,18 +85,19 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct _stat st;
|
struct _stat st;
|
||||||
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
||||||
if (path[strlen(path) - 1] == '/') {
|
if (str_endswith(path, PATHSEP))
|
||||||
path[strlen(path) - 1] = '\0';
|
|
||||||
|
memset(path + (strlen(path) - strlen(PATHSEP)), 0x00, strlen(PATHSEP));
|
||||||
result = _stat(path, &st);
|
result = _stat(path, &st);
|
||||||
path[strlen(path)] = '/';
|
strncat(path, PATHSEP, strlen(PATHSEP));
|
||||||
} else {
|
} else {
|
||||||
result = _stat(path, &st);
|
result = _stat(path, &st);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
result = stat(path, &st);
|
result = stat(path, &st);
|
||||||
#endif
|
#endif
|
||||||
if ((result != 0) && create_home) {
|
if ((result != 0) && create_home) {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (_mkdir(path))
|
if (_mkdir(path))
|
||||||
|
@ -108,8 +109,8 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
|
||||||
free(path);
|
free(path);
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (subdir != NULL) {
|
if (subdir != NULL) {
|
||||||
pathlen += strlen(subdir);
|
pathlen += strlen(subdir);
|
||||||
char *tmp = realloc(path, pathlen * sizeof(char));
|
char *tmp = realloc(path, pathlen * sizeof(char));
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
|
@ -144,22 +145,22 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
*foundpath = path;
|
*foundpath = path;
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
pathlen += strlen(filename);
|
pathlen += strlen(filename);
|
||||||
char *tmp = realloc(path, pathlen * sizeof(char));
|
char *tmp = realloc(path, pathlen *sizeof(char));
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
//free(path);
|
//free(path);
|
||||||
return PM3_EMALLOC;
|
return PM3_EMALLOC;
|
||||||
}
|
}
|
||||||
path = tmp;
|
path = tmp;
|
||||||
strcat(path, filename);
|
strcat(path, filename);
|
||||||
*foundpath = path;
|
*foundpath = path;
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) {
|
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue