Skip to content

Commit

Permalink
dirname: fix visual studio version
Browse files Browse the repository at this point in the history
hackish way to keep same function behavior as mingw/linux
the string result can't be freed on linux...

Not thread safe, but we dont care for our usage...
  • Loading branch information
tpruvot committed Feb 12, 2015
1 parent 13529dd commit 99d6dfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ static __inline int setpriority(int which, int who, int prio)
typedef int ssize_t;

#include <stdlib.h>
// This static var is made to be compatible with linux/mingw (no free on string result)
// This is not thread safe but we only use that once on process start
static char dirname_buffer[_MAX_PATH] = { 0 };
static __inline char * dirname(char *file) {
char buffer[_MAX_PATH] = { 0 };
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
char drive[_MAX_DRIVE] = { 0 };
char dir[_MAX_DIR] = { 0 };
char fname[_MAX_FNAME], ext[_MAX_EXT];
_splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
sprintf(buffer, "%s%s", drive, dir);
return &buffer[0];
if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') {
dir[strlen(dir) - 1] = '\0';
}
sprintf(dirname_buffer, "%s%s", drive, dir);
return &dirname_buffer[0];
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ void get_defconfig_path(char *out, size_t bufsize, char *argv0)
char *cmd = strdup(argv0);
char *dir = dirname(cmd);
const char *sep = strstr(dir, "\\") ? "\\" : "/";
struct stat info = { 0 };
#ifdef WIN32
snprintf(out, bufsize, "%s\\cpuminer\\cpuminer-conf.json", getenv("APPDATA"));
#else
snprintf(out, bufsize, "%s\\.cpuminer\\cpuminer-conf.json", getenv("HOME"));
#endif
struct stat info;
if (dir && stat(out, &info) != 0) {
snprintf(out, bufsize, "%s%scpuminer-conf.json", dir, sep);
}
Expand Down

0 comments on commit 99d6dfb

Please sign in to comment.