Don't duplicate string and ctype functions 2 (or even 3) times... we have stringlib...
[reactos.git] / reactos / lib / ntdll / stdlib / splitp.c
1 #include <ntdll.h>
2
3 /*
4 * @implemented
5 */
6 void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
7 {
8 char* tmp_drive;
9 char* tmp_dir;
10 char* tmp_ext;
11
12 tmp_drive = (char*)strchr(path,':');
13 if (drive) {
14 if (tmp_drive) {
15 strncpy(drive,tmp_drive-1,2);
16 *(drive+2) = 0;
17 } else {
18 *drive = 0;
19 }
20 }
21 if (!tmp_drive) {
22 tmp_drive = (char*)path - 1;
23 }
24
25 tmp_dir = (char*)strrchr(path,'\\');
26 if (dir) {
27 if (tmp_dir) {
28 strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
29 *(dir+(tmp_dir-tmp_drive)) = 0;
30 } else {
31 *dir =0;
32 }
33 }
34
35 tmp_ext = (char*)strrchr(path,'.');
36 if (!tmp_ext) {
37 tmp_ext = (char*)path+strlen(path);
38 }
39 if (ext) {
40 strcpy(ext,tmp_ext);
41 }
42
43 if (tmp_dir) {
44 strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
45 *(fname+(tmp_ext-tmp_dir-1)) = 0;
46 } else {
47 strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
48 *(fname+(tmp_ext-path))=0;
49 }
50 }
51