strdup replaced with strcpy. Common part for mac and linux is combined.
@@ -26,18 +26,7 @@ static char g_xdag_current_path[4096] = {0};
void xdag_init_path(char *path)
{
- char *pathcopy = strdup(path);
-#if defined (__APPLE__)|| defined (__MACOS__)
- char *prefix = dirname(pathcopy);
- if (*prefix != '/' && *prefix != '\\') {
- char buf[PATH_MAX];
- getcwd(buf, PATH_MAX);
- sprintf(g_xdag_current_path, "%s/%s", buf, prefix);
- } else {
- sprintf(g_xdag_current_path, "%s", prefix);
- }
- free(prefix);
-#elif _WIN32
+#ifdef _WIN32
char szPath[MAX_PATH];
char szBuffer[MAX_PATH];
char *pszFile;
@@ -48,6 +37,8 @@ void xdag_init_path(char *path)
strcpy(g_xdag_current_path, szBuffer);
#else
+ char pathcopy[PATH_MAX];
+ strcpy(pathcopy, path);
char *prefix = dirname(pathcopy);
if (*prefix != '/' && *prefix != '\\') {
char buf[PATH_MAX];
@@ -56,6 +47,9 @@ void xdag_init_path(char *path)
} else {
sprintf(g_xdag_current_path, "%s", prefix);
}
+#if defined (__APPLE__)|| defined (__MACOS__)
+ free(prefix);
+#endif
#endif
const size_t pathLen = strlen(g_xdag_current_path);
@@ -63,8 +57,6 @@ void xdag_init_path(char *path)
g_xdag_current_path[pathLen] = *DELIMITER;
g_xdag_current_path[pathLen + 1] = 0;
}
-
- free(pathcopy);
}
FILE* xdag_open_file(const char *path, const char *mode)
