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