[MSI]
[reactos.git] / reactos / lib / sdk / crt / string / splitp.c
1 #include <precomp.h>
2 #include <tchar.h>
3
4 /*
5 * @implemented
6 */
7 void _tsplitpath(const _TCHAR* path, _TCHAR* drive, _TCHAR* dir, _TCHAR* fname, _TCHAR* ext)
8 {
9 _TCHAR* tmp_drive = NULL;
10 _TCHAR* tmp_dir = NULL;
11 _TCHAR* tmp_ext = NULL;
12
13 tmp_drive = (_TCHAR*)_tcschr(path,':');
14 if (drive)
15 {
16 if (tmp_drive)
17 {
18 _tcsncpy(drive,tmp_drive-1,2);
19 *(drive+2) = 0;
20 }
21 else
22 {
23 *drive = 0;
24 }
25 }
26 if (!tmp_drive)
27 {
28 tmp_drive = (_TCHAR*)path - 1;
29 }
30
31 tmp_dir = (_TCHAR*)_tcsrchr(path,'\\');
32 if (dir)
33 {
34 if (tmp_dir)
35 {
36 _tcsncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
37 *(dir+(tmp_dir-tmp_drive)) = 0;
38 }
39 else
40 {
41 *dir =0;
42 }
43 }
44
45 /* If the dot is before the last dir separator, it's part
46 * of a directory name, not the start of the extension */
47 if (!tmp_ext || tmp_ext < tmp_dir)
48 {
49 tmp_ext = (_TCHAR*)path+_tcslen(path);
50 }
51 if (ext)
52 {
53 _tcscpy(ext,tmp_ext);
54 }
55
56 if (fname)
57 {
58 if (tmp_dir)
59 {
60 _tcsncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
61 *(fname+(tmp_ext-tmp_dir-1)) = 0;
62 }
63 else
64 {
65 _tcsncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
66 *(fname+(tmp_ext-path))=0;
67 }
68 }
69 }