Skip to content

Commit 7efe754

Browse files
committed
Common: fixed _splitpath() linux implementations
1 parent ebaee68 commit 7efe754

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Common/PlatformLinux.inl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,31 @@ inline void _splitpath (
105105
strcpy(drive, "");
106106

107107
if(dir) {
108-
strcpy(dir, dirname(tmp));
108+
char tmp_dir[PATH_MAX] = {0};
109+
strcpy(tmp_dir, tmp); // W/A for fname broking
110+
strcpy(dir, dirname(tmp_dir)); // This eval modify dirname argument!!!
109111
if (dir[0] && dir[strlen(dir) - 1] != '/')
110112
strcat(dir, "/");
111113
}
112114

113115
if(fname)
116+
{
114117
strcpy(fname, basename(tmp));
118+
char *pos = strrchr(fname, '.');
119+
if(pos != NULL)
120+
*pos = 0;
121+
}
122+
123+
if(ext)
124+
{
125+
char tmp_ext[NAME_MAX] = { 0 };
126+
strcpy(tmp_ext, basename(tmp));
127+
char *pos = strrchr(fname, '.');
128+
if(pos != NULL)
129+
strcpy(ext, pos + 1);
130+
else
131+
strcpy(ext, "");
132+
}
115133
}
116134

117135
#include <iostream>

0 commit comments

Comments
 (0)