20536c67ebc43110eef78c010c2bf73b0ee72d31
[reactos.git] / lib / msvcrt / stdlib / splitp.c
1 #include <msvcrt/stdlib.h>
2 #include <msvcrt/string.h>
3
4 void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext )
5 {
6         char *tmp_drive;
7         char *tmp_dir;
8         char *tmp_ext;
9
10         tmp_drive = (char *)strchr(path,':');
11         if ( tmp_drive != (char *)NULL ) {
12                 strncpy(drive,tmp_drive-1,1);
13                 *(drive+1) = 0;
14         }
15         else {
16                 *drive = 0; 
17                 tmp_drive = (char *)path;
18         }
19
20         tmp_dir = (char *)strrchr(path,'\\');
21         if( tmp_dir != NULL && tmp_dir != tmp_drive + 1 ) {
22                 strncpy(dir,tmp_drive+1,tmp_dir - tmp_drive);
23                 *(dir + (tmp_dir - tmp_drive)) = 0;
24         }
25         else    
26                 *dir =0;
27
28         tmp_ext = ( char *)strrchr(path,'.');
29         if ( tmp_ext != NULL ) {
30                 strcpy(ext,tmp_ext);
31         }
32         else
33         {
34                 *ext = 0; 
35                 tmp_ext = (char *)path+strlen(path);
36         }
37     if ( tmp_dir != NULL ) {
38                 strncpy(fname,tmp_dir+1,tmp_ext - tmp_dir - 1);
39                 *(fname + (tmp_ext - tmp_dir -1)) = 0;
40         }
41         else
42         {
43                 strncpy(fname,path,tmp_ext - path);
44                 *(fname+(tmp_ext-path))=0;
45         }
46 }
47
48 void _wsplitpath( const wchar_t *path, wchar_t *drive, wchar_t *dir, wchar_t *fname, wchar_t *ext )
49 {
50         wchar_t *tmp_drive;
51         wchar_t *tmp_dir;
52         wchar_t *tmp_ext;
53
54         tmp_drive = (wchar_t *)wcschr(path,L':');
55         if ( tmp_drive != (wchar_t *)NULL ) {
56                 wcsncpy(drive,tmp_drive-1,1);
57                 *(drive+1) = 0;
58         }
59         else {
60                 *drive = 0;
61                 tmp_drive = (wchar_t *)path;
62         }
63
64         tmp_dir = (wchar_t *)wcsrchr(path,L'\\');
65         if( tmp_dir != NULL && tmp_dir != tmp_drive + 1 ) {
66                 wcsncpy(dir,tmp_drive+1,tmp_dir - tmp_drive);
67                 *(dir + (tmp_dir - tmp_drive)) = 0;
68         }
69         else
70                 *dir =0;
71
72         tmp_ext = (wchar_t *)wcsrchr(path,L'.');
73         if ( tmp_ext != NULL ) {
74                 wcscpy(ext,tmp_ext);
75         }
76         else
77         {
78                 *ext = 0;
79                 tmp_ext = (wchar_t *)path+wcslen(path);
80         }
81
82         if ( tmp_dir != NULL ) {
83                 wcsncpy(fname,tmp_dir+1,tmp_ext - tmp_dir - 1);
84                 *(fname + (tmp_ext - tmp_dir -1)) = 0;
85         }
86         else
87         {
88                 wcsncpy(fname,path,tmp_ext - path);
89                 *(fname+(tmp_ext-path))=0;
90         }
91 }