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 qsort( base
, nmemb
, size
, compar
);
105 /*********************************************************************
108 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
109 size_t size
, int(*compar
)(const void *, const void *) )
112 return lfind( key
, base
, &n
, size
, compar
);
116 /*********************************************************************
119 char * __cdecl
NTDLL_strcat( char *dst
, const char *src
)
121 return strcat( dst
, src
);
125 /*********************************************************************
128 char * __cdecl
NTDLL_strchr( const char *str
, int c
)
130 return strchr( str
, c
);
134 /*********************************************************************
137 int __cdecl
NTDLL_strcmp( const char *str1
, const char *str2
)
139 return strcmp( str1
, str2
);
143 /*********************************************************************
146 char * __cdecl
NTDLL_strcpy( char *dst
, const char *src
)
148 return strcpy( dst
, src
);
152 /*********************************************************************
155 size_t __cdecl
NTDLL_strcspn( const char *str
, const char *reject
)
157 return strcspn( str
, reject
);
161 /*********************************************************************
164 size_t __cdecl
NTDLL_strlen( const char *str
)
166 return strlen( str
);
170 /*********************************************************************
173 char * __cdecl
NTDLL_strncat( char *dst
, const char *src
, size_t len
)
175 return strncat( dst
, src
, len
);
179 /*********************************************************************
182 int __cdecl
NTDLL_strncmp( const char *str1
, const char *str2
, size_t len
)
184 return strncmp( str1
, str2
, len
);
188 /*********************************************************************
191 char * __cdecl
NTDLL_strncpy( char *dst
, const char *src
, size_t len
)
193 return strncpy( dst
, src
, len
);
197 /*********************************************************************
200 char * __cdecl
NTDLL_strpbrk( const char *str
, const char *accept
)
202 return strpbrk( str
, accept
);
206 /*********************************************************************
209 char * __cdecl
NTDLL_strrchr( const char *str
, int c
)
211 return strrchr( str
, c
);
215 /*********************************************************************
218 size_t __cdecl
NTDLL_strspn( const char *str
, const char *accept
)
220 return strspn( str
, accept
);
224 /*********************************************************************
227 char * __cdecl
NTDLL_strstr( const char *haystack
, const char *needle
)
229 return strstr( haystack
, needle
);
233 /*********************************************************************
236 void * __cdecl
_memccpy( void *dst
, const void *src
, int c
, size_t n
)
238 return memccpy( dst
, src
, c
, n
);
242 /*********************************************************************
245 * Compare two blocks of memory as strings, ignoring case.
248 * s1 [I] First string to compare to s2
249 * s2 [I] Second string to compare to s1
250 * len [I] Number of bytes to compare
253 * An integer less than, equal to, or greater than zero indicating that
254 * s1 is less than, equal to or greater than s2 respectively.
257 * Any Nul characters in s1 or s2 are ignored. This function always
258 * compares up to len bytes or the first place where s1 and s2 differ.
260 INT __cdecl
_memicmp( LPCSTR s1
, LPCSTR s2
, DWORD len
)
265 if ((ret
= tolower(*s1
) - tolower(*s2
))) break;
273 /*********************************************************************
277 int __cdecl
_stricmp( LPCSTR str1
, LPCSTR str2
)
279 return strcasecmp( str1
, str2
);
283 /*********************************************************************
284 * _strnicmp (NTDLL.@)
286 int __cdecl
_strnicmp( LPCSTR str1
, LPCSTR str2
, size_t n
)
288 return strncasecmp( str1
, str2
, n
);
292 /*********************************************************************
295 * Convert a string to upper case.
298 * str [I/O] String to convert
301 * str. There is no error return, if str is NULL or invalid, this
302 * function will crash.
304 LPSTR __cdecl
_strupr( LPSTR str
)
307 for ( ; *str
; str
++) *str
= toupper(*str
);
312 /*********************************************************************
315 * Convert a string to lowercase
318 * str [I/O] String to convert
321 * str. There is no error return, if str is NULL or invalid, this
322 * function will crash.
324 LPSTR __cdecl
_strlwr( LPSTR str
)
327 for ( ; *str
; str
++) *str
= tolower(*str
);
332 /*********************************************************************
335 int __cdecl
NTDLL_tolower( int c
)
341 /*********************************************************************
344 int __cdecl
NTDLL_toupper( int c
)
350 /*********************************************************************
353 int __cdecl
NTDLL_isalnum( int c
)
359 /*********************************************************************
362 int __cdecl
NTDLL_isalpha( int c
)
368 /*********************************************************************
371 int __cdecl
NTDLL_iscntrl( int c
)
377 /*********************************************************************
380 int __cdecl
NTDLL_isdigit( int c
)
386 /*********************************************************************
389 int __cdecl
NTDLL_isgraph( int c
)
395 /*********************************************************************
398 int __cdecl
NTDLL_islower( int c
)
404 /*********************************************************************
407 int __cdecl
NTDLL_isprint( int c
)
413 /*********************************************************************
416 int __cdecl
NTDLL_ispunct( int c
)
422 /*********************************************************************
425 int __cdecl
NTDLL_isspace( int c
)
431 /*********************************************************************
434 int __cdecl
NTDLL_isupper( int c
)
440 /*********************************************************************
443 int __cdecl
NTDLL_isxdigit( int c
)
445 return isxdigit( c
);
449 /*********************************************************************
452 long __cdecl
NTDLL_strtol( const char *nptr
, char **endptr
, int base
)
454 return strtol( nptr
, endptr
, base
);
458 /*********************************************************************
461 unsigned long __cdecl
NTDLL_strtoul( const char *nptr
, char **endptr
, int base
)
463 return strtoul( nptr
, endptr
, base
);
467 /*********************************************************************
470 int __cdecl
NTDLL_atoi( const char *nptr
)
476 /*********************************************************************
479 long __cdecl
NTDLL_atol( const char *nptr
)
485 /*********************************************************************
488 * Convert an unsigned long integer to a string.
494 * - Converts value to a Nul terminated string which is copied to str.
495 * - The maximum length of the copied str is 33 bytes.
496 * - Does not check if radix is in the range of 2 to 36.
497 * - If str is NULL it crashes, as the native function does.
499 char * __cdecl
_ultoa(
500 unsigned long value
, /* [I] Value to be converted */
501 char *str
, /* [O] Destination for the converted value */
502 int radix
) /* [I] Number base for conversion */
512 digit
= value
% radix
;
513 value
= value
/ radix
;
515 *--pos
= '0' + digit
;
517 *--pos
= 'a' + digit
- 10;
519 } while (value
!= 0L);
521 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
526 /*********************************************************************
529 * Convert a long integer to a string.
535 * - Converts value to a Nul terminated string which is copied to str.
536 * - The maximum length of the copied str is 33 bytes. If radix
537 * is 10 and value is negative, the value is converted with sign.
538 * - Does not check if radix is in the range of 2 to 36.
539 * - If str is NULL it crashes, as the native function does.
541 char * __cdecl
_ltoa(
542 long value
, /* [I] Value to be converted */
543 char *str
, /* [O] Destination for the converted value */
544 int radix
) /* [I] Number base for conversion */
552 if (value
< 0 && radix
== 10) {
567 *--pos
= '0' + digit
;
569 *--pos
= 'a' + digit
- 10;
577 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
582 /*********************************************************************
585 * Converts an integer to a string.
591 * - Converts value to a '\0' terminated string which is copied to str.
592 * - The maximum length of the copied str is 33 bytes. If radix
593 * is 10 and value is negative, the value is converted with sign.
594 * - Does not check if radix is in the range of 2 to 36.
595 * - If str is NULL it crashes, as the native function does.
597 char * __cdecl
_itoa(
598 int value
, /* [I] Value to be converted */
599 char *str
, /* [O] Destination for the converted value */
600 int radix
) /* [I] Number base for conversion */
602 return _ltoa(value
, str
, radix
);
606 /*********************************************************************
609 * Converts a large unsigned integer to a string.
615 * - Converts value to a '\0' terminated string which is copied to str.
616 * - The maximum length of the copied str is 65 bytes.
617 * - Does not check if radix is in the range of 2 to 36.
618 * - If str is NULL it crashes, as the native function does.
620 char * __cdecl
_ui64toa(
621 ULONGLONG value
, /* [I] Value to be converted */
622 char *str
, /* [O] Destination for the converted value */
623 int radix
) /* [I] Number base for conversion */
633 digit
= value
% radix
;
634 value
= value
/ radix
;
636 *--pos
= '0' + digit
;
638 *--pos
= 'a' + digit
- 10;
640 } while (value
!= 0L);
642 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
647 /*********************************************************************
650 * Converts a large integer to a string.
656 * - Converts value to a Nul terminated string which is copied to str.
657 * - The maximum length of the copied str is 65 bytes. If radix
658 * is 10 and value is negative, the value is converted with sign.
659 * - Does not check if radix is in the range of 2 to 36.
660 * - If str is NULL it crashes, as the native function does.
663 * - The native DLL converts negative values (for base 10) wrong:
664 *| -1 is converted to -18446744073709551615
665 *| -2 is converted to -18446744073709551614
666 *| -9223372036854775807 is converted to -9223372036854775809
667 *| -9223372036854775808 is converted to -9223372036854775808
668 * The native msvcrt _i64toa function and our ntdll _i64toa function
669 * do not have this bug.
671 char * __cdecl
_i64toa(
672 LONGLONG value
, /* [I] Value to be converted */
673 char *str
, /* [O] Destination for the converted value */
674 int radix
) /* [I] Number base for conversion */
682 if (value
< 0 && radix
== 10) {
697 *--pos
= '0' + digit
;
699 *--pos
= 'a' + digit
- 10;
707 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
712 /*********************************************************************
715 * Convert a string to a large integer.
718 * str [I] String to be converted
721 * Success: The integer value represented by str.
722 * Failure: 0. Note that this cannot be distinguished from a successful
723 * return, if the string contains "0".
726 * - Accepts: {whitespace} [+|-] {digits}
727 * - No check is made for value overflow, only the lower 64 bits are assigned.
728 * - If str is NULL it crashes, as the native function does.
730 LONGLONG __cdecl
_atoi64( char *str
)
732 ULONGLONG RunningTotal
= 0;
735 while (*str
== ' ' || (*str
>= '\011' && *str
<= '\015')) {
741 } else if (*str
== '-') {
746 while (*str
>= '0' && *str
<= '9') {
747 RunningTotal
= RunningTotal
* 10 + *str
- '0';
751 return bMinus
? -RunningTotal
: RunningTotal
;
755 /*********************************************************************
758 int __cdecl
NTDLL_sprintf( char *str
, const char *format
, ... )
762 va_start( valist
, format
);
763 ret
= vsprintf( str
, format
, valist
);
769 /*********************************************************************
772 int __cdecl
NTDLL_vsprintf( char *str
, const char *format
, va_list args
)
774 return vsprintf( str
, format
, args
);
778 /*********************************************************************
779 * _snprintf (NTDLL.@)
781 int __cdecl
_snprintf( char *str
, size_t len
, const char *format
, ... )
785 va_start( valist
, format
);
786 ret
= vsnprintf( str
, len
, format
, valist
);
792 /*********************************************************************
793 * _vsnprintf (NTDLL.@)
795 int __cdecl
_vsnprintf( char *str
, size_t len
, const char *format
, va_list args
)
797 return vsnprintf( str
, len
, format
, args
);
801 /*********************************************************************
804 int __cdecl
NTDLL_sscanf( const char *str
, const char *format
, ... )
808 va_start( valist
, format
);
809 ret
= vsscanf( str
, format
, valist
);
815 /*********************************************************************
816 * _splitpath (NTDLL.@)
818 * Split a path into its component pieces.
821 * inpath [I] Path to split
822 * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
823 * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
824 * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
825 * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
830 void __cdecl
_splitpath(const char* inpath
, char * drv
, char * dir
,
831 char* fname
, char * ext
)
835 if (inpath
[0] && inpath
[1] == ':')
845 else if (drv
) drv
[0] = 0;
847 /* look for end of directory part */
849 for (p
= inpath
; *p
; p
++) if (*p
== '/' || *p
== '\\') end
= p
+ 1;
851 if (end
) /* got a directory */
855 memcpy( dir
, inpath
, end
- inpath
);
856 dir
[end
- inpath
] = 0;
860 else if (dir
) dir
[0] = 0;
862 /* look for extension: what's after the last dot */
864 for (p
= inpath
; *p
; p
++) if (*p
== '.') end
= p
;
866 if (!end
) end
= p
; /* there's no extension */
870 memcpy( fname
, inpath
, end
- inpath
);
871 fname
[end
- inpath
] = 0;
873 if (ext
) strcpy( ext
, end
);