[8429] | 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 |
|
---|
[9986] | 27 |
|
---|
[8429] | 28 | #include "windef.h"
|
---|
| 29 |
|
---|
| 30 | /*********************************************************************
|
---|
| 31 | * _memicmp (NTDLL.@)
|
---|
| 32 | */
|
---|
[9986] | 33 | INT __cdecl NTDLL__memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
|
---|
[8429] | 34 | {
|
---|
| 35 | int ret = 0;
|
---|
| 36 | while (len--)
|
---|
| 37 | {
|
---|
| 38 | if ((ret = tolower(*s1) - tolower(*s2))) break;
|
---|
| 39 | s1++;
|
---|
| 40 | s2++;
|
---|
| 41 | }
|
---|
| 42 | return ret;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /*********************************************************************
|
---|
| 46 | * _strupr (NTDLL.@)
|
---|
| 47 | */
|
---|
| 48 | LPSTR __cdecl _strupr( LPSTR str )
|
---|
| 49 | {
|
---|
| 50 | LPSTR ret = str;
|
---|
| 51 | for ( ; *str; str++) *str = toupper(*str);
|
---|
| 52 | return ret;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /*********************************************************************
|
---|
| 56 | * _strlwr (NTDLL.@)
|
---|
| 57 | *
|
---|
| 58 | * convert a string in place to lowercase
|
---|
| 59 | */
|
---|
| 60 | LPSTR __cdecl _strlwr( LPSTR str )
|
---|
| 61 | {
|
---|
| 62 | LPSTR ret = str;
|
---|
| 63 | for ( ; *str; str++) *str = tolower(*str);
|
---|
| 64 | return ret;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /*********************************************************************
|
---|
| 69 | * _ultoa (NTDLL.@)
|
---|
| 70 | */
|
---|
| 71 | #ifdef __WIN32OS2__
|
---|
[9986] | 72 | LPSTR __cdecl NTDLL_ultoa( unsigned long value, LPSTR str, INT radix )
|
---|
[8429] | 73 | #else
|
---|
[9986] | 74 | LPSTR __cdecl _ultoa( unsigned long value, LPSTR str, INT radix )
|
---|
[8429] | 75 | #endif
|
---|
| 76 | {
|
---|
[9986] | 77 | char buffer[33];
|
---|
| 78 | char *pos;
|
---|
| 79 | int digit;
|
---|
[8429] | 80 |
|
---|
[9986] | 81 | pos = &buffer[32];
|
---|
| 82 | *pos = '\0';
|
---|
| 83 |
|
---|
| 84 | do {
|
---|
| 85 | digit = value % radix;
|
---|
| 86 | value = value / radix;
|
---|
| 87 | if (digit < 10) {
|
---|
| 88 | *--pos = '0' + digit;
|
---|
| 89 | } else {
|
---|
| 90 | *--pos = 'a' + digit - 10;
|
---|
| 91 | } /* if */
|
---|
| 92 | } while (value != 0L);
|
---|
| 93 |
|
---|
| 94 | memcpy(str, pos, &buffer[32] - pos + 1);
|
---|
| 95 | return str;
|
---|
[8429] | 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | /*********************************************************************
|
---|
| 100 | * _ltoa (NTDLL.@)
|
---|
[9986] | 101 | *
|
---|
| 102 | * RETURNS
|
---|
| 103 | * Always returns str.
|
---|
| 104 | *
|
---|
| 105 | * NOTES
|
---|
| 106 | * Converts value to a '\0' terminated string which is copied to str.
|
---|
| 107 | * The maximum length of the copied str is 33 bytes. If radix
|
---|
| 108 | * is 10 and value is negative, the value is converted with sign.
|
---|
| 109 | * Does not check if radix is in the range of 2 to 36.
|
---|
| 110 | * If str is NULL it crashes, as the native function does.
|
---|
[8429] | 111 | */
|
---|
[9986] | 112 |
|
---|
[8429] | 113 | #ifdef __WIN32OS2__
|
---|
[9986] | 114 | LPSTR __cdecl NTDLL_ltoa( long value, LPSTR str, INT radix )
|
---|
[8429] | 115 | #else
|
---|
[9986] | 116 | LPSTR __cdecl _ltoa( long value, LPSTR str, INT radix )
|
---|
[8429] | 117 | #endif
|
---|
| 118 | {
|
---|
[9986] | 119 | unsigned long val;
|
---|
| 120 | int negative;
|
---|
| 121 | char buffer[33];
|
---|
| 122 | char *pos;
|
---|
| 123 | int digit;
|
---|
| 124 |
|
---|
| 125 | if (value < 0 && radix == 10) {
|
---|
| 126 | negative = 1;
|
---|
| 127 | val = -value;
|
---|
| 128 | } else {
|
---|
| 129 | negative = 0;
|
---|
| 130 | val = value;
|
---|
| 131 | } /* if */
|
---|
| 132 |
|
---|
| 133 | pos = &buffer[32];
|
---|
| 134 | *pos = '\0';
|
---|
| 135 |
|
---|
| 136 | do {
|
---|
| 137 | digit = val % radix;
|
---|
| 138 | val = val / radix;
|
---|
| 139 | if (digit < 10) {
|
---|
| 140 | *--pos = '0' + digit;
|
---|
| 141 | } else {
|
---|
| 142 | *--pos = 'a' + digit - 10;
|
---|
| 143 | } /* if */
|
---|
| 144 | } while (val != 0L);
|
---|
| 145 |
|
---|
| 146 | if (negative) {
|
---|
| 147 | *--pos = '-';
|
---|
| 148 | } /* if */
|
---|
| 149 |
|
---|
| 150 | memcpy(str, pos, &buffer[32] - pos + 1);
|
---|
| 151 | return str;
|
---|
[8429] | 152 | }
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | /*********************************************************************
|
---|
| 156 | * _itoa (NTDLL.@)
|
---|
| 157 | */
|
---|
| 158 | #ifdef __WIN32OS2__
|
---|
| 159 | LPSTR __cdecl NTDLL_itoa( int x, LPSTR buf, INT radix )
|
---|
| 160 | #else
|
---|
| 161 | LPSTR __cdecl _itoa( int x, LPSTR buf, INT radix )
|
---|
| 162 | #endif
|
---|
| 163 | {
|
---|
[9986] | 164 | return NTDLL_ltoa( x, buf, radix );
|
---|
[8429] | 165 | }
|
---|
| 166 |
|
---|
[9986] | 167 | /*********************************************************************
|
---|
| 168 | * _ui64toa (NTDLL.@)
|
---|
| 169 | *
|
---|
| 170 | * Converts a large unsigned integer to a string.
|
---|
| 171 | *
|
---|
| 172 | * Assigns a '\0' terminated string to str and returns str.
|
---|
| 173 | * Does not check if radix is in the range of 2 to 36 (as native DLL).
|
---|
| 174 | * For str == NULL just crashes (as native DLL).
|
---|
| 175 | */
|
---|
| 176 | char * __cdecl _ui64toa( ULONGLONG value, char *str, int radix )
|
---|
| 177 | {
|
---|
| 178 | char buffer[65];
|
---|
| 179 | char *pos;
|
---|
| 180 | int digit;
|
---|
[8429] | 181 |
|
---|
[9986] | 182 | pos = &buffer[64];
|
---|
| 183 | *pos = '\0';
|
---|
| 184 |
|
---|
| 185 | do {
|
---|
| 186 | digit = value % radix;
|
---|
| 187 | value = value / radix;
|
---|
| 188 | if (digit < 10) {
|
---|
| 189 | *--pos = '0' + digit;
|
---|
| 190 | } else {
|
---|
| 191 | *--pos = 'a' + digit - 10;
|
---|
| 192 | } /* if */
|
---|
| 193 | } while (value != 0L);
|
---|
| 194 |
|
---|
| 195 | memcpy(str, pos, &buffer[64] - pos + 1);
|
---|
| 196 | return str;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
[8429] | 200 | /*********************************************************************
|
---|
[9986] | 201 | * _i64toa (NTDLL.@)
|
---|
| 202 | *
|
---|
| 203 | * Converts a large integer to a string.
|
---|
| 204 | *
|
---|
| 205 | * Assigns a '\0' terminated string to str and returns str. If radix
|
---|
| 206 | * is 10 and value is negative, the value is converted with sign.
|
---|
| 207 | * Does not check if radix is in the range of 2 to 36 (as native DLL).
|
---|
| 208 | * For str == NULL just crashes (as native DLL).
|
---|
| 209 | *
|
---|
| 210 | * Difference:
|
---|
| 211 | * - The native DLL converts negative values (for base 10) wrong:
|
---|
| 212 | * -1 is converted to -18446744073709551615
|
---|
| 213 | * -2 is converted to -18446744073709551614
|
---|
| 214 | * -9223372036854775807 is converted to -9223372036854775809
|
---|
| 215 | * -9223372036854775808 is converted to -9223372036854775808
|
---|
| 216 | * The native msvcrt _i64toa function and our ntdll function do
|
---|
| 217 | * not have this bug.
|
---|
| 218 | */
|
---|
| 219 | char * __cdecl _i64toa( LONGLONG value, char *str, int radix )
|
---|
| 220 | {
|
---|
| 221 | ULONGLONG val;
|
---|
| 222 | int negative;
|
---|
| 223 | char buffer[65];
|
---|
| 224 | char *pos;
|
---|
| 225 | int digit;
|
---|
| 226 |
|
---|
| 227 | if (value < 0 && radix == 10) {
|
---|
| 228 | negative = 1;
|
---|
| 229 | val = -value;
|
---|
| 230 | } else {
|
---|
| 231 | negative = 0;
|
---|
| 232 | val = value;
|
---|
| 233 | } /* if */
|
---|
| 234 |
|
---|
| 235 | pos = &buffer[64];
|
---|
| 236 | *pos = '\0';
|
---|
| 237 |
|
---|
| 238 | do {
|
---|
| 239 | digit = val % radix;
|
---|
| 240 | val = val / radix;
|
---|
| 241 | if (digit < 10) {
|
---|
| 242 | *--pos = '0' + digit;
|
---|
| 243 | } else {
|
---|
| 244 | *--pos = 'a' + digit - 10;
|
---|
| 245 | } /* if */
|
---|
| 246 | } while (val != 0L);
|
---|
| 247 |
|
---|
| 248 | if (negative) {
|
---|
| 249 | *--pos = '-';
|
---|
| 250 | } /* if */
|
---|
| 251 |
|
---|
| 252 | memcpy(str, pos, &buffer[64] - pos + 1);
|
---|
| 253 | return str;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | /*********************************************************************
|
---|
| 258 | * _atoi64 (NTDLL.@)
|
---|
| 259 | *
|
---|
| 260 | * Converts a string to a large integer.
|
---|
| 261 | *
|
---|
| 262 | * On success it returns the integer value otherwise it returns 0.
|
---|
| 263 | * Accepts: {whitespace} [+|-] {digits}
|
---|
| 264 | * No check of overflow: Just assigns lower 64 bits (as native DLL).
|
---|
| 265 | * Does not check for str != NULL (as native DLL).
|
---|
| 266 | */
|
---|
| 267 | LONGLONG __cdecl _atoi64( char *str )
|
---|
| 268 | {
|
---|
| 269 | ULONGLONG RunningTotal = 0;
|
---|
| 270 | char bMinus = 0;
|
---|
| 271 |
|
---|
| 272 | while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
|
---|
| 273 | str++;
|
---|
| 274 | } /* while */
|
---|
| 275 |
|
---|
| 276 | if (*str == '+') {
|
---|
| 277 | str++;
|
---|
| 278 | } else if (*str == '-') {
|
---|
| 279 | bMinus = 1;
|
---|
| 280 | str++;
|
---|
| 281 | } /* if */
|
---|
| 282 |
|
---|
| 283 | while (*str >= '0' && *str <= '9') {
|
---|
| 284 | RunningTotal = RunningTotal * 10 + *str - '0';
|
---|
| 285 | str++;
|
---|
| 286 | } /* while */
|
---|
| 287 |
|
---|
| 288 | return bMinus ? -RunningTotal : RunningTotal;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | /*********************************************************************
|
---|
[8429] | 293 | * _splitpath (NTDLL.@)
|
---|
| 294 | */
|
---|
| 295 | #ifdef __WIN32OS2__
|
---|
| 296 | void __cdecl NTDLL_splitpath(const char* inpath, char * drv, char * dir,
|
---|
| 297 | char* fname, char * ext )
|
---|
| 298 | #else
|
---|
| 299 | void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
---|
| 300 | char* fname, char * ext )
|
---|
| 301 | #endif
|
---|
| 302 | {
|
---|
| 303 | /* Modified PD code from 'snippets' collection. */
|
---|
| 304 | char ch, *ptr, *p;
|
---|
| 305 | char pathbuff[MAX_PATH], *path=pathbuff;
|
---|
| 306 |
|
---|
| 307 | strcpy(pathbuff, inpath);
|
---|
| 308 |
|
---|
| 309 | /* convert slashes to backslashes for searching */
|
---|
| 310 | for (ptr = (char*)path; *ptr; ++ptr)
|
---|
| 311 | if ('/' == *ptr)
|
---|
| 312 | *ptr = '\\';
|
---|
| 313 |
|
---|
| 314 | /* look for drive spec */
|
---|
| 315 | if ('\0' != (ptr = strchr(path, ':')))
|
---|
| 316 | {
|
---|
| 317 | ++ptr;
|
---|
| 318 | if (drv)
|
---|
| 319 | {
|
---|
| 320 | strncpy(drv, path, ptr - path);
|
---|
| 321 | drv[ptr - path] = '\0';
|
---|
| 322 | }
|
---|
| 323 | path = ptr;
|
---|
| 324 | }
|
---|
| 325 | else if (drv)
|
---|
| 326 | *drv = '\0';
|
---|
| 327 |
|
---|
| 328 | /* find rightmost backslash or leftmost colon */
|
---|
| 329 | if (NULL == (ptr = strrchr(path, '\\')))
|
---|
| 330 | ptr = (strchr(path, ':'));
|
---|
| 331 |
|
---|
| 332 | if (!ptr)
|
---|
| 333 | {
|
---|
| 334 | ptr = (char *)path; /* no path */
|
---|
| 335 | if (dir)
|
---|
| 336 | *dir = '\0';
|
---|
| 337 | }
|
---|
| 338 | else
|
---|
| 339 | {
|
---|
| 340 | ++ptr; /* skip the delimiter */
|
---|
| 341 | if (dir)
|
---|
| 342 | {
|
---|
| 343 | ch = *ptr;
|
---|
| 344 | *ptr = '\0';
|
---|
| 345 | strcpy(dir, path);
|
---|
| 346 | *ptr = ch;
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | if (NULL == (p = strrchr(ptr, '.')))
|
---|
| 351 | {
|
---|
| 352 | if (fname)
|
---|
| 353 | strcpy(fname, ptr);
|
---|
| 354 | if (ext)
|
---|
| 355 | *ext = '\0';
|
---|
| 356 | }
|
---|
| 357 | else
|
---|
| 358 | {
|
---|
| 359 | *p = '\0';
|
---|
| 360 | if (fname)
|
---|
| 361 | strcpy(fname, ptr);
|
---|
| 362 | *p = '.';
|
---|
| 363 | if (ext)
|
---|
| 364 | strcpy(ext, p);
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /* Fix pathological case - Win returns ':' as part of the
|
---|
| 368 | * directory when no drive letter is given.
|
---|
| 369 | */
|
---|
| 370 | if (drv && drv[0] == ':')
|
---|
| 371 | {
|
---|
| 372 | *drv = '\0';
|
---|
| 373 | if (dir)
|
---|
| 374 | {
|
---|
| 375 | pathbuff[0] = ':';
|
---|
| 376 | pathbuff[1] = '\0';
|
---|
| 377 | strcat(pathbuff,dir);
|
---|
| 378 | strcpy(dir,pathbuff);
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 | }
|
---|