@@ -89,47 +89,48 @@ inline void Sleep(int ms)
8989 usleep (ms * 1000 );
9090}
9191
92- #include < libgen.h>
93- inline void _splitpath (
94- const char * path, // Path Input
95- char * drive, // Drive : Output
96- char * dir, // Directory : Output
97- char * fname, // Filename : Output
98- char * ext // Extension : Output
99- ){
100- char tmp[PATH_MAX] = {0 };
101- if (!realpath (path, tmp))
102- strcpy (tmp, path);
92+ inline void _splitpath (const char * path, // Path Input
93+ char * drive, // Drive : Output
94+ char * dir, // Directory : Output
95+ char * fname, // Filename : Output
96+ char * ext // Extension : Output
97+ )
98+ {
99+ const char *p, *end;
103100
104101 if (drive)
105102 strcpy (drive, " " );
106103
107- if (dir) {
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!!!
111- if (dir[0 ] && dir[strlen (dir) - 1 ] != ' /' )
112- strcat (dir, " /" );
104+ end = NULL ;
105+ for (p = path; *p; p++)
106+ if (*p == ' /' || *p == ' \\ ' )
107+ end = p + 1 ;
108+
109+ if (end)
110+ {
111+ if (dir)
112+ {
113+ memcpy (dir, path, end - path);
114+ dir[end - path] = 0 ;
115+ }
116+ path = end;
113117 }
118+ else if (dir)
119+ dir[0 ] = 0 ;
120+
121+ end = strchr (path, ' .' );
122+
123+ if (!end)
124+ end = p;
114125
115126 if (fname)
116127 {
117- strcpy (fname, basename (tmp));
118- char *pos = strrchr (fname, ' .' );
119- if (pos != NULL )
120- *pos = 0 ;
128+ memcpy (fname, path, end - path);
129+ fname[end - path] = 0 ;
121130 }
122131
123132 if (ext)
124- {
125- char tmp_ext[NAME_MAX] = { 0 };
126- strcpy (tmp_ext, basename (tmp));
127- char *pos = strrchr (tmp_ext, ' .' );
128- if (pos != NULL )
129- strcpy (ext, pos);
130- else
131- strcpy (ext, " " );
132- }
133+ strcpy (ext, end);
133134}
134135
135136#include < iostream>
@@ -350,7 +351,12 @@ inline int _filelength(int fd)
350351#define _read read
351352#define _set_new_handler std::set_new_handler
352353#define _finite isfinite
353- #define _mkdir (dir ) mkdir(dir, S_IRWXU)
354+ inline int _mkdir (const char *dir)
355+ {
356+ while (char * sep = strchr ((char *)dir, ' \\ ' )) *sep = ' /' ;
357+ return mkdir (dir, S_IRWXU);
358+ }
359+
354360#define _wtoi (arg ) wcstol(arg, NULL , 10 )
355361#define _wtoi64 (arg ) wcstoll(arg, NULL , 10 )
356362#undef min
0 commit comments