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