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"
37 /*********************************************************************
40 void * __cdecl
NTDLL_memchr( const void *ptr
, int c
, size_t n
)
42 return memchr( ptr
, c
, n
);
46 /*********************************************************************
49 int __cdecl
NTDLL_memcmp( const void *ptr1
, const void *ptr2
, size_t n
)
51 return memcmp( ptr1
, ptr2
, n
);
55 /*********************************************************************
59 * Behaves like memmove.
61 void * __cdecl
NTDLL_memcpy( void *dst
, const void *src
, size_t n
)
63 return memmove( dst
, src
, n
);
67 /*********************************************************************
70 void * __cdecl
NTDLL_memmove( void *dst
, const void *src
, size_t n
)
72 return memmove( dst
, src
, n
);
76 /*********************************************************************
79 void * __cdecl
NTDLL_memset( void *dst
, int c
, size_t n
)
81 return memset( dst
, c
, n
);
85 /*********************************************************************
88 void * __cdecl
NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
89 size_t size
, int (*compar
)(const void *, const void *) )
91 return bsearch( key
, base
, nmemb
, size
, compar
);
95 /*********************************************************************
98 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
99 int(*compar
)(const void *, const void *) )
101 return qsort( base
, nmemb
, size
, compar
);
105 /*********************************************************************
108 void * __cdecl
_lfind( const void *key
, const void *base
, size_t *nmemb
,
109 size_t size
, int(*compar
)(const void *, const void *) )
111 return lfind( key
, base
, nmemb
, size
, compar
);
115 /*********************************************************************
118 char * __cdecl
NTDLL_strcat( char *dst
, const char *src
)
120 return strcat( dst
, src
);
124 /*********************************************************************
127 char * __cdecl
NTDLL_strchr( const char *str
, int c
)
129 return strchr( str
, c
);
133 /*********************************************************************
136 int __cdecl
NTDLL_strcmp( const char *str1
, const char *str2
)
138 return strcmp( str1
, str2
);
142 /*********************************************************************
145 char * __cdecl
NTDLL_strcpy( char *dst
, const char *src
)
147 return strcpy( dst
, src
);
151 /*********************************************************************
154 size_t __cdecl
NTDLL_strcspn( const char *str
, const char *reject
)
156 return strcspn( str
, reject
);
160 /*********************************************************************
163 size_t __cdecl
NTDLL_strlen( const char *str
)
165 return strlen( str
);
169 /*********************************************************************
172 char * __cdecl
NTDLL_strncat( char *dst
, const char *src
, size_t len
)
174 return strncat( dst
, src
, len
);
178 /*********************************************************************
181 int __cdecl
NTDLL_strncmp( const char *str1
, const char *str2
, size_t len
)
183 return strncmp( str1
, str2
, len
);
187 /*********************************************************************
190 char * __cdecl
NTDLL_strncpy( char *dst
, const char *src
, size_t len
)
192 return strncpy( dst
, src
, len
);
196 /*********************************************************************
199 char * __cdecl
NTDLL_strpbrk( const char *str
, const char *accept
)
201 return strpbrk( str
, accept
);
205 /*********************************************************************
208 char * __cdecl
NTDLL_strrchr( const char *str
, int c
)
210 return strrchr( str
, c
);
214 /*********************************************************************
217 size_t __cdecl
NTDLL_strspn( const char *str
, const char *accept
)
219 return strspn( str
, accept
);
223 /*********************************************************************
226 char * __cdecl
NTDLL_strstr( const char *haystack
, const char *needle
)
228 return strstr( haystack
, needle
);
232 /*********************************************************************
235 void * __cdecl
_memccpy( void *dst
, const void *src
, int c
, size_t n
)
237 return memccpy( dst
, src
, c
, n
);
241 /*********************************************************************
244 * Compare two blocks of memory as strings, ignoring case.
247 * s1 [I] First string to compare to s2
248 * s2 [I] Second string to compare to s1
249 * len [I] Number of bytes to compare
252 * An integer less than, equal to, or greater than zero indicating that
253 * s1 is less than, equal to or greater than s2 respectively.
256 * Any Nul characters in s1 or s2 are ignored. This function always
257 * compares up to len bytes or the first place where s1 and s2 differ.
259 INT __cdecl
_memicmp( LPCSTR s1
, LPCSTR s2
, DWORD len
)
264 if ((ret
= tolower(*s1
) - tolower(*s2
))) break;
272 /*********************************************************************
276 int __cdecl
_stricmp( LPCSTR str1
, LPCSTR str2
)
278 return strcasecmp( str1
, str2
);
282 /*********************************************************************
283 * _strnicmp (NTDLL.@)
285 int __cdecl
_strnicmp( LPCSTR str1
, LPCSTR str2
, size_t n
)
287 return strncasecmp( str1
, str2
, n
);
291 /*********************************************************************
294 * Convert a string to upper case.
297 * str [I/O] String to convert
300 * str. There is no error return, if str is NULL or invalid, this
301 * function will crash.
303 LPSTR __cdecl
_strupr( LPSTR str
)
306 for ( ; *str
; str
++) *str
= toupper(*str
);
311 /*********************************************************************
314 * Convert a string to lowercase
317 * str [I/O] String to convert
320 * str. There is no error return, if str is NULL or invalid, this
321 * function will crash.
323 LPSTR __cdecl
_strlwr( LPSTR str
)
326 for ( ; *str
; str
++) *str
= tolower(*str
);
331 /*********************************************************************
334 int __cdecl
NTDLL_tolower( int c
)
340 /*********************************************************************
343 int __cdecl
NTDLL_toupper( int c
)
349 /*********************************************************************
352 int __cdecl
NTDLL_isalnum( int c
)
358 /*********************************************************************
361 int __cdecl
NTDLL_isalpha( int c
)
367 /*********************************************************************
370 int __cdecl
NTDLL_iscntrl( int c
)
376 /*********************************************************************
379 int __cdecl
NTDLL_isdigit( int c
)
385 /*********************************************************************
388 int __cdecl
NTDLL_isgraph( int c
)
394 /*********************************************************************
397 int __cdecl
NTDLL_islower( int c
)
403 /*********************************************************************
406 int __cdecl
NTDLL_isprint( int c
)
412 /*********************************************************************
415 int __cdecl
NTDLL_ispunct( int c
)
421 /*********************************************************************
424 int __cdecl
NTDLL_isspace( int c
)
430 /*********************************************************************
433 int __cdecl
NTDLL_isupper( int c
)
439 /*********************************************************************
442 int __cdecl
NTDLL_isxdigit( int c
)
444 return isxdigit( c
);
448 /*********************************************************************
451 long __cdecl
NTDLL_strtol( const char *nptr
, char **endptr
, int base
)
453 return strtol( nptr
, endptr
, base
);
457 /*********************************************************************
460 unsigned long __cdecl
NTDLL_strtoul( const char *nptr
, char **endptr
, int base
)
462 return strtoul( nptr
, endptr
, base
);
466 /*********************************************************************
469 int __cdecl
NTDLL_atoi( const char *nptr
)
475 /*********************************************************************
478 long __cdecl
NTDLL_atol( const char *nptr
)
484 /*********************************************************************
487 * Convert an unsigned long integer to a string.
493 * - Converts value to a Nul terminated string which is copied to str.
494 * - The maximum length of the copied str is 33 bytes.
495 * - Does not check if radix is in the range of 2 to 36.
496 * - If str is NULL it crashes, as the native function does.
498 char * __cdecl
_ultoa(
499 unsigned long value
, /* [I] Value to be converted */
500 char *str
, /* [O] Destination for the converted value */
501 int radix
) /* [I] Number base for conversion */
511 digit
= value
% radix
;
512 value
= value
/ radix
;
514 *--pos
= '0' + digit
;
516 *--pos
= 'a' + digit
- 10;
518 } while (value
!= 0L);
520 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
525 /*********************************************************************
528 * Convert a long integer to a string.
534 * - Converts value to a Nul terminated string which is copied to str.
535 * - The maximum length of the copied str is 33 bytes. If radix
536 * is 10 and value is negative, the value is converted with sign.
537 * - Does not check if radix is in the range of 2 to 36.
538 * - If str is NULL it crashes, as the native function does.
540 char * __cdecl
_ltoa(
541 long value
, /* [I] Value to be converted */
542 char *str
, /* [O] Destination for the converted value */
543 int radix
) /* [I] Number base for conversion */
551 if (value
< 0 && radix
== 10) {
566 *--pos
= '0' + digit
;
568 *--pos
= 'a' + digit
- 10;
576 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
581 /*********************************************************************
584 * Converts an integer to a string.
590 * - Converts value to a '\0' terminated string which is copied to str.
591 * - The maximum length of the copied str is 33 bytes. If radix
592 * is 10 and value is negative, the value is converted with sign.
593 * - Does not check if radix is in the range of 2 to 36.
594 * - If str is NULL it crashes, as the native function does.
596 char * __cdecl
_itoa(
597 int value
, /* [I] Value to be converted */
598 char *str
, /* [O] Destination for the converted value */
599 int radix
) /* [I] Number base for conversion */
601 return _ltoa(value
, str
, radix
);
605 /*********************************************************************
608 * Converts a large unsigned integer to a string.
614 * - Converts value to a '\0' terminated string which is copied to str.
615 * - The maximum length of the copied str is 65 bytes.
616 * - Does not check if radix is in the range of 2 to 36.
617 * - If str is NULL it crashes, as the native function does.
619 char * __cdecl
_ui64toa(
620 ULONGLONG value
, /* [I] Value to be converted */
621 char *str
, /* [O] Destination for the converted value */
622 int radix
) /* [I] Number base for conversion */
632 digit
= value
% radix
;
633 value
= value
/ radix
;
635 *--pos
= '0' + digit
;
637 *--pos
= 'a' + digit
- 10;
639 } while (value
!= 0L);
641 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
646 /*********************************************************************
649 * Converts a large integer to a string.
655 * - Converts value to a Nul terminated string which is copied to str.
656 * - The maximum length of the copied str is 65 bytes. If radix
657 * is 10 and value is negative, the value is converted with sign.
658 * - Does not check if radix is in the range of 2 to 36.
659 * - If str is NULL it crashes, as the native function does.
662 * - The native DLL converts negative values (for base 10) wrong:
663 *| -1 is converted to -18446744073709551615
664 *| -2 is converted to -18446744073709551614
665 *| -9223372036854775807 is converted to -9223372036854775809
666 *| -9223372036854775808 is converted to -9223372036854775808
667 * The native msvcrt _i64toa function and our ntdll _i64toa function
668 * do not have this bug.
670 char * __cdecl
_i64toa(
671 LONGLONG value
, /* [I] Value to be converted */
672 char *str
, /* [O] Destination for the converted value */
673 int radix
) /* [I] Number base for conversion */
681 if (value
< 0 && radix
== 10) {
696 *--pos
= '0' + digit
;
698 *--pos
= 'a' + digit
- 10;
706 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
711 /*********************************************************************
714 * Convert a string to a large integer.
717 * str [I] String to be converted
720 * Success: The integer value represented by str.
721 * Failure: 0. Note that this cannot be distinguished from a successful
722 * return, if the string contains "0".
725 * - Accepts: {whitespace} [+|-] {digits}
726 * - No check is made for value overflow, only the lower 64 bits are assigned.
727 * - If str is NULL it crashes, as the native function does.
729 LONGLONG __cdecl
_atoi64( char *str
)
731 ULONGLONG RunningTotal
= 0;
734 while (*str
== ' ' || (*str
>= '\011' && *str
<= '\015')) {
740 } else if (*str
== '-') {
745 while (*str
>= '0' && *str
<= '9') {
746 RunningTotal
= RunningTotal
* 10 + *str
- '0';
750 return bMinus
? -RunningTotal
: RunningTotal
;
754 /*********************************************************************
757 int __cdecl
NTDLL_sprintf( char *str
, const char *format
, ... )
761 va_start( valist
, format
);
762 ret
= vsprintf( str
, format
, valist
);
768 /*********************************************************************
771 int __cdecl
NTDLL_vsprintf( char *str
, const char *format
, va_list args
)
773 return vsprintf( str
, format
, args
);
777 /*********************************************************************
778 * _snprintf (NTDLL.@)
780 int __cdecl
_snprintf( char *str
, size_t len
, const char *format
, ... )
784 va_start( valist
, format
);
785 ret
= vsnprintf( str
, len
, format
, valist
);
791 /*********************************************************************
792 * _vsnprintf (NTDLL.@)
794 int __cdecl
_vsnprintf( char *str
, size_t len
, const char *format
, va_list args
)
796 return vsnprintf( str
, len
, format
, args
);
800 /*********************************************************************
803 int __cdecl
NTDLL_sscanf( const char *str
, const char *format
, ... )
807 va_start( valist
, format
);
808 ret
= vsscanf( str
, format
, valist
);
814 /*********************************************************************
815 * _splitpath (NTDLL.@)
817 * Split a path into its component pieces.
820 * inpath [I] Path to split
821 * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
822 * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
823 * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
824 * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
829 void __cdecl
_splitpath(const char* inpath
, char * drv
, char * dir
,
830 char* fname
, char * ext
)
834 if (inpath
[0] && inpath
[1] == ':')
844 else if (drv
) drv
[0] = 0;
846 /* look for end of directory part */
848 for (p
= inpath
; *p
; p
++) if (*p
== '/' || *p
== '\\') end
= p
+ 1;
850 if (end
) /* got a directory */
854 memcpy( dir
, inpath
, end
- inpath
);
855 dir
[end
- inpath
] = 0;
859 else if (dir
) dir
[0] = 0;
861 /* look for extension: what's after the last dot */
863 for (p
= inpath
; *p
; p
++) if (*p
== '.') end
= p
;
865 if (!end
) end
= p
; /* there's no extension */
869 memcpy( fname
, inpath
, end
- inpath
);
870 fname
[end
- inpath
] = 0;
872 if (ext
) strcpy( ext
, end
);