2 * NTDLL string functions
4 * Copyright 2000 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
6 * Copyright 2003 Thomas Mertes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
36 /*********************************************************************
39 void * __cdecl NTDLL_memchr( const void *ptr, int c, size_t n )
41 return memchr( ptr, c, n );
45 /*********************************************************************
48 int __cdecl NTDLL_memcmp( const void *ptr1, const void *ptr2, size_t n )
50 return memcmp( ptr1, ptr2, n );
54 /*********************************************************************
58 * Behaves like memmove.
60 void * __cdecl NTDLL_memcpy( void *dst, const void *src, size_t n )
62 return memmove( dst, src, n );
66 /*********************************************************************
69 void * __cdecl NTDLL_memmove( void *dst, const void *src, size_t n )
71 return memmove( dst, src, n );
75 /*********************************************************************
78 void * __cdecl NTDLL_memset( void *dst, int c, size_t n )
80 return memset( dst, c, n );
84 /*********************************************************************
87 char * __cdecl NTDLL_strcat( char *dst, const char *src )
89 return strcat( dst, src );
93 /*********************************************************************
96 char * __cdecl NTDLL_strchr( const char *str, int c )
98 return strchr( str, c );
102 /*********************************************************************
105 int __cdecl NTDLL_strcmp( const char *str1, const char *str2 )
107 return strcmp( str1, str2 );
111 /*********************************************************************
114 char * __cdecl NTDLL_strcpy( char *dst, const char *src )
116 return strcpy( dst, src );
120 /*********************************************************************
123 size_t __cdecl NTDLL_strcspn( const char *str, const char *reject )
125 return strcspn( str, reject );
129 /*********************************************************************
132 size_t __cdecl NTDLL_strlen( const char *str )
134 return strlen( str );
138 /*********************************************************************
141 char * __cdecl NTDLL_strncat( char *dst, const char *src, size_t len )
143 return strncat( dst, src, len );
147 /*********************************************************************
150 int __cdecl NTDLL_strncmp( const char *str1, const char *str2, size_t len )
152 return strncmp( str1, str2, len );
156 /*********************************************************************
159 char * __cdecl NTDLL_strncpy( char *dst, const char *src, size_t len )
161 return strncpy( dst, src, len );
165 /*********************************************************************
168 char * __cdecl NTDLL_strpbrk( const char *str, const char *accept )
170 return strpbrk( str, accept );
174 /*********************************************************************
177 char * __cdecl NTDLL_strrchr( const char *str, int c )
179 return strrchr( str, c );
183 /*********************************************************************
186 size_t __cdecl NTDLL_strspn( const char *str, const char *accept )
188 return strspn( str, accept );
192 /*********************************************************************
195 char * __cdecl NTDLL_strstr( const char *haystack, const char *needle )
197 return strstr( haystack, needle );
201 /*********************************************************************
204 void * __cdecl _memccpy( void *dst, const void *src, int c, size_t n )
206 return memccpy( dst, src, c, n );
210 /*********************************************************************
213 * Compare two blocks of memory as strings, ignoring case.
216 * s1 [I] First string to compare to s2
217 * s2 [I] Second string to compare to s1
218 * len [I] Number of bytes to compare
221 * An integer less than, equal to, or greater than zero indicating that
222 * s1 is less than, equal to or greater than s2 respectively.
225 * Any Nul characters in s1 or s2 are ignored. This function always
226 * compares up to len bytes or the first place where s1 and s2 differ.
228 INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
233 if ((ret = tolower(*s1) - tolower(*s2))) break;
241 /*********************************************************************
245 int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 )
247 return strcasecmp( str1, str2 );
251 /*********************************************************************
252 * _strnicmp (NTDLL.@)
254 int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
256 return strncasecmp( str1, str2, n );
260 /*********************************************************************
263 * Convert a string to upper case.
266 * str [I/O] String to convert
269 * str. There is no error return, if str is NULL or invalid, this
270 * function will crash.
272 LPSTR __cdecl _strupr( LPSTR str )
275 for ( ; *str; str++) *str = toupper(*str);
280 /*********************************************************************
283 * Convert a string to lowercase
286 * str [I/O] String to convert
289 * str. There is no error return, if str is NULL or invalid, this
290 * function will crash.
292 LPSTR __cdecl _strlwr( LPSTR str )
295 for ( ; *str; str++) *str = tolower(*str);
300 /*********************************************************************
303 int __cdecl NTDLL_tolower( int c )
309 /*********************************************************************
312 int __cdecl NTDLL_toupper( int c )
318 /*********************************************************************
321 int __cdecl NTDLL_isalnum( int c )
327 /*********************************************************************
330 int __cdecl NTDLL_isalpha( int c )
336 /*********************************************************************
339 int __cdecl NTDLL_iscntrl( int c )
345 /*********************************************************************
348 int __cdecl NTDLL_isdigit( int c )
354 /*********************************************************************
357 int __cdecl NTDLL_isgraph( int c )
363 /*********************************************************************
366 int __cdecl NTDLL_islower( int c )
372 /*********************************************************************
375 int __cdecl NTDLL_isprint( int c )
381 /*********************************************************************
384 int __cdecl NTDLL_ispunct( int c )
390 /*********************************************************************
393 int __cdecl NTDLL_isspace( int c )
399 /*********************************************************************
402 int __cdecl NTDLL_isupper( int c )
408 /*********************************************************************
411 int __cdecl NTDLL_isxdigit( int c )
413 return isxdigit( c );
417 /*********************************************************************
418 * __isascii (NTDLL.@)
420 int CDECL NTDLL___isascii(int c)
422 return (unsigned)c < 0x80;
426 /*********************************************************************
427 * __toascii (NTDLL.@)
429 int CDECL NTDLL___toascii(int c)
431 return (unsigned)c & 0x7f;
435 /*********************************************************************
438 int CDECL NTDLL___iscsym(int c)
440 return (c < 127 && (isalnum(c) || c == '_'));
444 /*********************************************************************
445 * __iscsymf (NTDLL.@)
447 int CDECL NTDLL___iscsymf(int c)
449 return (c < 127 && (isalpha(c) || c == '_'));
453 /*********************************************************************
456 int CDECL NTDLL__toupper(int c)
458 return c - 0x20; /* sic */
462 /*********************************************************************
465 int CDECL NTDLL__tolower(int c)
467 return c + 0x20; /* sic */
471 /*********************************************************************
474 LONG __cdecl NTDLL_strtol( const char *nptr, char **endptr, int base )
476 return strtol( nptr, endptr, base );
480 /*********************************************************************
483 ULONG __cdecl NTDLL_strtoul( const char *nptr, char **endptr, int base )
485 return strtoul( nptr, endptr, base );
489 /*********************************************************************
492 * Convert an unsigned long integer to a string.
498 * - Converts value to a Nul terminated string which is copied to str.
499 * - The maximum length of the copied str is 33 bytes.
500 * - Does not check if radix is in the range of 2 to 36.
501 * - If str is NULL it crashes, as the native function does.
503 char * __cdecl _ultoa(
504 ULONG value, /* [I] Value to be converted */
505 char *str, /* [O] Destination for the converted value */
506 int radix) /* [I] Number base for conversion */
516 digit = value % radix;
517 value = value / radix;
519 *--pos = '0' + digit;
521 *--pos = 'a' + digit - 10;
523 } while (value != 0L);
525 memcpy(str, pos, &buffer[32] - pos + 1);
530 /*********************************************************************
533 * Convert a long integer to a string.
539 * - Converts value to a Nul terminated string which is copied to str.
540 * - The maximum length of the copied str is 33 bytes. If radix
541 * is 10 and value is negative, the value is converted with sign.
542 * - Does not check if radix is in the range of 2 to 36.
543 * - If str is NULL it crashes, as the native function does.
545 char * __cdecl _ltoa(
546 LONG value, /* [I] Value to be converted */
547 char *str, /* [O] Destination for the converted value */
548 int radix) /* [I] Number base for conversion */
556 if (value < 0 && radix == 10) {
571 *--pos = '0' + digit;
573 *--pos = 'a' + digit - 10;
581 memcpy(str, pos, &buffer[32] - pos + 1);
586 /*********************************************************************
589 * Converts an integer to a string.
595 * - Converts value to a '\0' terminated string which is copied to str.
596 * - The maximum length of the copied str is 33 bytes. If radix
597 * is 10 and value is negative, the value is converted with sign.
598 * - Does not check if radix is in the range of 2 to 36.
599 * - If str is NULL it crashes, as the native function does.
601 char * __cdecl _itoa(
602 int value, /* [I] Value to be converted */
603 char *str, /* [O] Destination for the converted value */
604 int radix) /* [I] Number base for conversion */
606 return _ltoa(value, str, radix);
610 /*********************************************************************
613 * Converts a large unsigned integer to a string.
619 * - Converts value to a '\0' terminated string which is copied to str.
620 * - The maximum length of the copied str is 65 bytes.
621 * - Does not check if radix is in the range of 2 to 36.
622 * - If str is NULL it crashes, as the native function does.
624 char * __cdecl _ui64toa(
625 ULONGLONG value, /* [I] Value to be converted */
626 char *str, /* [O] Destination for the converted value */
627 int radix) /* [I] Number base for conversion */
637 digit = value % radix;
638 value = value / radix;
640 *--pos = '0' + digit;
642 *--pos = 'a' + digit - 10;
644 } while (value != 0L);
646 memcpy(str, pos, &buffer[64] - pos + 1);
651 /*********************************************************************
654 * Converts a large integer to a string.
660 * - Converts value to a Nul terminated string which is copied to str.
661 * - The maximum length of the copied str is 65 bytes. If radix
662 * is 10 and value is negative, the value is converted with sign.
663 * - Does not check if radix is in the range of 2 to 36.
664 * - If str is NULL it crashes, as the native function does.
667 * - The native DLL converts negative values (for base 10) wrong:
668 *| -1 is converted to -18446744073709551615
669 *| -2 is converted to -18446744073709551614
670 *| -9223372036854775807 is converted to -9223372036854775809
671 *| -9223372036854775808 is converted to -9223372036854775808
672 * The native msvcrt _i64toa function and our ntdll _i64toa function
673 * do not have this bug.
675 char * __cdecl _i64toa(
676 LONGLONG value, /* [I] Value to be converted */
677 char *str, /* [O] Destination for the converted value */
678 int radix) /* [I] Number base for conversion */
686 if (value < 0 && radix == 10) {
701 *--pos = '0' + digit;
703 *--pos = 'a' + digit - 10;
711 memcpy(str, pos, &buffer[64] - pos + 1);
716 /*********************************************************************
719 * Convert a string to a large integer.
722 * str [I] String to be converted
725 * Success: The integer value represented by str.
726 * Failure: 0. Note that this cannot be distinguished from a successful
727 * return, if the string contains "0".
730 * - Accepts: {whitespace} [+|-] {digits}
731 * - No check is made for value overflow, only the lower 64 bits are assigned.
732 * - If str is NULL it crashes, as the native function does.
734 LONGLONG __cdecl _atoi64( const char *str )
736 ULONGLONG RunningTotal = 0;
739 while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
745 } else if (*str == '-') {
750 while (*str >= '0' && *str <= '9') {
751 RunningTotal = RunningTotal * 10 + *str - '0';
755 return bMinus ? -RunningTotal : RunningTotal;
759 /*********************************************************************
762 int __cdecl NTDLL_atoi( const char *nptr )
764 return _atoi64( nptr );
768 /*********************************************************************
771 LONG __cdecl NTDLL_atol( const char *nptr )
773 return _atoi64( nptr );
777 /*********************************************************************
780 int __cdecl NTDLL_sscanf( const char *str, const char *format, ... )
784 va_start( valist, format );
785 ret = vsscanf( str, format, valist );
791 /*********************************************************************
792 * _splitpath (NTDLL.@)
794 * Split a path into its component pieces.
797 * inpath [I] Path to split
798 * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
799 * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
800 * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
801 * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
806 void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
807 char* fname, char * ext )
811 if (inpath[0] && inpath[1] == ':')
821 else if (drv) drv[0] = 0;
823 /* look for end of directory part */
825 for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
827 if (end) /* got a directory */
831 memcpy( dir, inpath, end - inpath );
832 dir[end - inpath] = 0;
836 else if (dir) dir[0] = 0;
838 /* look for extension: what's after the last dot */
840 for (p = inpath; *p; p++) if (*p == '.') end = p;
842 if (!end) end = p; /* there's no extension */
846 memcpy( fname, inpath, end - inpath );
847 fname[end - inpath] = 0;
849 if (ext) strcpy( ext, end );