Store in the server all the window information accessible with
[wine] / dlls / ntdll / string.c
1 /*
2  * NTDLL string functions
3  *
4  * Copyright 2000 Alexandre Julliard
5  * Copyright 2000 Jon Griffiths
6  */
7
8 #include "config.h"
9
10 #include <ctype.h>
11 #include <string.h>
12
13 #include "windef.h"
14
15 /*********************************************************************
16  *                  _memicmp   (NTDLL.@)
17  */
18 INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
19 {
20     int ret = 0;
21     while (len--)
22     {
23         if ((ret = tolower(*s1) - tolower(*s2))) break;
24         s1++;
25         s2++;
26     }
27     return ret;
28 }
29
30 /*********************************************************************
31  *                  _strupr   (NTDLL.@)
32  */
33 LPSTR __cdecl _strupr( LPSTR str )
34 {
35     LPSTR ret = str;
36     for ( ; *str; str++) *str = toupper(*str);
37     return ret;
38 }
39
40 /*********************************************************************
41  *                  _strlwr   (NTDLL.@)
42  *
43  * convert a string in place to lowercase 
44  */
45 LPSTR __cdecl _strlwr( LPSTR str )
46 {
47     LPSTR ret = str;
48     for ( ; *str; str++) *str = tolower(*str);
49     return ret;
50 }
51
52
53 /*********************************************************************
54  *                  _ultoa   (NTDLL.@)
55  */
56 LPSTR  __cdecl _ultoa( unsigned long x, LPSTR buf, INT radix )
57 {
58     char buffer[32], *p;
59
60     p = buffer + sizeof(buffer);
61     *--p = 0;
62     do
63     {
64         int rem = x % radix;
65         *--p = (rem <= 9) ? rem + '0' : rem + 'a' - 10;
66         x /= radix;
67     } while (x);
68     strcpy( buf, p );
69     return buf;
70 }
71
72
73 /*********************************************************************
74  *                  _ltoa   (NTDLL.@)
75  */
76 LPSTR  __cdecl _ltoa( long x, LPSTR buf, INT radix )
77 {
78     LPSTR p = buf;
79     if (x < 0)
80     {
81         *p++ = '-';
82         x = -x;
83     }
84     _ultoa( x, p, radix );
85     return buf;
86 }
87
88
89 /*********************************************************************
90  *                  _itoa           (NTDLL.@)
91  */
92 LPSTR  __cdecl _itoa( int x, LPSTR buf, INT radix )
93 {
94     return _ltoa( x, buf, radix );
95 }
96
97
98 /*********************************************************************
99  *              _splitpath (NTDLL.@)
100  */
101 void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
102                         char* fname, char * ext )
103 {
104   /* Modified PD code from 'snippets' collection. */
105   char ch, *ptr, *p;
106   char pathbuff[MAX_PATH], *path=pathbuff;
107
108   strcpy(pathbuff, inpath);
109
110   /* convert slashes to backslashes for searching */
111   for (ptr = (char*)path; *ptr; ++ptr)
112     if ('/' == *ptr)
113       *ptr = '\\';
114
115   /* look for drive spec */
116   if ('\0' != (ptr = strchr(path, ':')))
117   {
118     ++ptr;
119     if (drv)
120     {
121       strncpy(drv, path, ptr - path);
122       drv[ptr - path] = '\0';
123     }
124     path = ptr;
125   }
126   else if (drv)
127     *drv = '\0';
128
129   /* find rightmost backslash or leftmost colon */
130   if (NULL == (ptr = strrchr(path, '\\')))
131     ptr = (strchr(path, ':'));
132
133   if (!ptr)
134   {
135     ptr = (char *)path; /* no path */
136     if (dir)
137       *dir = '\0';
138   }
139   else
140   {
141     ++ptr; /* skip the delimiter */
142     if (dir)
143     {
144       ch = *ptr;
145       *ptr = '\0';
146       strcpy(dir, path);
147       *ptr = ch;
148     }
149   }
150
151   if (NULL == (p = strrchr(ptr, '.')))
152   {
153     if (fname)
154       strcpy(fname, ptr);
155     if (ext)
156       *ext = '\0';
157   }
158   else
159   {
160     *p = '\0';
161     if (fname)
162       strcpy(fname, ptr);
163     *p = '.';
164     if (ext)
165       strcpy(ext, p);
166   }
167
168   /* Fix pathological case - Win returns ':' as part of the
169    * directory when no drive letter is given.
170    */
171   if (drv && drv[0] == ':')
172   {
173     *drv = '\0';
174     if (dir)
175     {
176       pathbuff[0] = ':';
177       pathbuff[1] = '\0';
178       strcat(pathbuff,dir);
179       strcpy(dir,pathbuff);
180     }
181   }
182 }