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