1 | /*
|
---|
2 | * NTDLL string functions
|
---|
3 | *
|
---|
4 | * Copyright 2000 Alexandre Julliard
|
---|
5 | * Copyright 2000 Jon Griffiths
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "config.h"
|
---|
23 |
|
---|
24 | #include <ctype.h>
|
---|
25 | #include <string.h>
|
---|
26 |
|
---|
27 | #include "windef.h"
|
---|
28 |
|
---|
29 | /*********************************************************************
|
---|
30 | * _memicmp (NTDLL.@)
|
---|
31 | */
|
---|
32 | INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
|
---|
33 | {
|
---|
34 | int ret = 0;
|
---|
35 | while (len--)
|
---|
36 | {
|
---|
37 | if ((ret = tolower(*s1) - tolower(*s2))) break;
|
---|
38 | s1++;
|
---|
39 | s2++;
|
---|
40 | }
|
---|
41 | return ret;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /*********************************************************************
|
---|
45 | * _strupr (NTDLL.@)
|
---|
46 | */
|
---|
47 | LPSTR __cdecl _strupr( LPSTR str )
|
---|
48 | {
|
---|
49 | LPSTR ret = str;
|
---|
50 | for ( ; *str; str++) *str = toupper(*str);
|
---|
51 | return ret;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /*********************************************************************
|
---|
55 | * _strlwr (NTDLL.@)
|
---|
56 | *
|
---|
57 | * convert a string in place to lowercase
|
---|
58 | */
|
---|
59 | LPSTR __cdecl _strlwr( LPSTR str )
|
---|
60 | {
|
---|
61 | LPSTR ret = str;
|
---|
62 | for ( ; *str; str++) *str = tolower(*str);
|
---|
63 | return ret;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /*********************************************************************
|
---|
68 | * _ultoa (NTDLL.@)
|
---|
69 | */
|
---|
70 | #ifdef __WIN32OS2__
|
---|
71 | LPSTR __cdecl NTDLL_ultoa( unsigned long x, LPSTR buf, INT radix )
|
---|
72 | #else
|
---|
73 | LPSTR __cdecl _ultoa( unsigned long x, LPSTR buf, INT radix )
|
---|
74 | #endif
|
---|
75 | {
|
---|
76 | char buffer[32], *p;
|
---|
77 |
|
---|
78 | p = buffer + sizeof(buffer);
|
---|
79 | *--p = 0;
|
---|
80 | do
|
---|
81 | {
|
---|
82 | int rem = x % radix;
|
---|
83 | *--p = (rem <= 9) ? rem + '0' : rem + 'a' - 10;
|
---|
84 | x /= radix;
|
---|
85 | } while (x);
|
---|
86 | strcpy( buf, p );
|
---|
87 | return buf;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /*********************************************************************
|
---|
92 | * _ltoa (NTDLL.@)
|
---|
93 | */
|
---|
94 | #ifdef __WIN32OS2__
|
---|
95 | LPSTR __cdecl NTDLL_ltoa( long x, LPSTR buf, INT radix )
|
---|
96 | #else
|
---|
97 | LPSTR __cdecl _ltoa( long x, LPSTR buf, INT radix )
|
---|
98 | #endif
|
---|
99 | {
|
---|
100 | LPSTR p = buf;
|
---|
101 | if (x < 0)
|
---|
102 | {
|
---|
103 | *p++ = '-';
|
---|
104 | x = -x;
|
---|
105 | }
|
---|
106 | _ultoa( x, p, radix );
|
---|
107 | return buf;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | /*********************************************************************
|
---|
112 | * _itoa (NTDLL.@)
|
---|
113 | */
|
---|
114 | #ifdef __WIN32OS2__
|
---|
115 | LPSTR __cdecl NTDLL_itoa( int x, LPSTR buf, INT radix )
|
---|
116 | #else
|
---|
117 | LPSTR __cdecl _itoa( int x, LPSTR buf, INT radix )
|
---|
118 | #endif
|
---|
119 | {
|
---|
120 | return _ltoa( x, buf, radix );
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /*********************************************************************
|
---|
125 | * _splitpath (NTDLL.@)
|
---|
126 | */
|
---|
127 | #ifdef __WIN32OS2__
|
---|
128 | void __cdecl NTDLL_splitpath(const char* inpath, char * drv, char * dir,
|
---|
129 | char* fname, char * ext )
|
---|
130 | #else
|
---|
131 | void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
---|
132 | char* fname, char * ext )
|
---|
133 | #endif
|
---|
134 | {
|
---|
135 | /* Modified PD code from 'snippets' collection. */
|
---|
136 | char ch, *ptr, *p;
|
---|
137 | char pathbuff[MAX_PATH], *path=pathbuff;
|
---|
138 |
|
---|
139 | strcpy(pathbuff, inpath);
|
---|
140 |
|
---|
141 | /* convert slashes to backslashes for searching */
|
---|
142 | for (ptr = (char*)path; *ptr; ++ptr)
|
---|
143 | if ('/' == *ptr)
|
---|
144 | *ptr = '\\';
|
---|
145 |
|
---|
146 | /* look for drive spec */
|
---|
147 | if ('\0' != (ptr = strchr(path, ':')))
|
---|
148 | {
|
---|
149 | ++ptr;
|
---|
150 | if (drv)
|
---|
151 | {
|
---|
152 | strncpy(drv, path, ptr - path);
|
---|
153 | drv[ptr - path] = '\0';
|
---|
154 | }
|
---|
155 | path = ptr;
|
---|
156 | }
|
---|
157 | else if (drv)
|
---|
158 | *drv = '\0';
|
---|
159 |
|
---|
160 | /* find rightmost backslash or leftmost colon */
|
---|
161 | if (NULL == (ptr = strrchr(path, '\\')))
|
---|
162 | ptr = (strchr(path, ':'));
|
---|
163 |
|
---|
164 | if (!ptr)
|
---|
165 | {
|
---|
166 | ptr = (char *)path; /* no path */
|
---|
167 | if (dir)
|
---|
168 | *dir = '\0';
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | ++ptr; /* skip the delimiter */
|
---|
173 | if (dir)
|
---|
174 | {
|
---|
175 | ch = *ptr;
|
---|
176 | *ptr = '\0';
|
---|
177 | strcpy(dir, path);
|
---|
178 | *ptr = ch;
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (NULL == (p = strrchr(ptr, '.')))
|
---|
183 | {
|
---|
184 | if (fname)
|
---|
185 | strcpy(fname, ptr);
|
---|
186 | if (ext)
|
---|
187 | *ext = '\0';
|
---|
188 | }
|
---|
189 | else
|
---|
190 | {
|
---|
191 | *p = '\0';
|
---|
192 | if (fname)
|
---|
193 | strcpy(fname, ptr);
|
---|
194 | *p = '.';
|
---|
195 | if (ext)
|
---|
196 | strcpy(ext, p);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* Fix pathological case - Win returns ':' as part of the
|
---|
200 | * directory when no drive letter is given.
|
---|
201 | */
|
---|
202 | if (drv && drv[0] == ':')
|
---|
203 | {
|
---|
204 | *drv = '\0';
|
---|
205 | if (dir)
|
---|
206 | {
|
---|
207 | pathbuff[0] = ':';
|
---|
208 | pathbuff[1] = '\0';
|
---|
209 | strcat(pathbuff,dir);
|
---|
210 | strcpy(dir,pathbuff);
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|