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 /*********************************************************************
420 LONG __cdecl
NTDLL_strtol( const char *nptr
, char **endptr
, int base
)
422 return strtol( nptr
, endptr
, base
);
426 /*********************************************************************
429 ULONG __cdecl
NTDLL_strtoul( const char *nptr
, char **endptr
, int base
)
431 return strtoul( nptr
, endptr
, base
);
435 /*********************************************************************
438 * Convert an unsigned long integer to a string.
444 * - Converts value to a Nul terminated string which is copied to str.
445 * - The maximum length of the copied str is 33 bytes.
446 * - Does not check if radix is in the range of 2 to 36.
447 * - If str is NULL it crashes, as the native function does.
449 char * __cdecl
_ultoa(
450 ULONG value
, /* [I] Value to be converted */
451 char *str
, /* [O] Destination for the converted value */
452 int radix
) /* [I] Number base for conversion */
462 digit
= value
% radix
;
463 value
= value
/ radix
;
465 *--pos
= '0' + digit
;
467 *--pos
= 'a' + digit
- 10;
469 } while (value
!= 0L);
471 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
476 /*********************************************************************
479 * Convert a long integer to a string.
485 * - Converts value to a Nul terminated string which is copied to str.
486 * - The maximum length of the copied str is 33 bytes. If radix
487 * is 10 and value is negative, the value is converted with sign.
488 * - Does not check if radix is in the range of 2 to 36.
489 * - If str is NULL it crashes, as the native function does.
491 char * __cdecl
_ltoa(
492 LONG value
, /* [I] Value to be converted */
493 char *str
, /* [O] Destination for the converted value */
494 int radix
) /* [I] Number base for conversion */
502 if (value
< 0 && radix
== 10) {
517 *--pos
= '0' + digit
;
519 *--pos
= 'a' + digit
- 10;
527 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
532 /*********************************************************************
535 * Converts an integer to a string.
541 * - Converts value to a '\0' terminated string which is copied to str.
542 * - The maximum length of the copied str is 33 bytes. If radix
543 * is 10 and value is negative, the value is converted with sign.
544 * - Does not check if radix is in the range of 2 to 36.
545 * - If str is NULL it crashes, as the native function does.
547 char * __cdecl
_itoa(
548 int value
, /* [I] Value to be converted */
549 char *str
, /* [O] Destination for the converted value */
550 int radix
) /* [I] Number base for conversion */
552 return _ltoa(value
, str
, radix
);
556 /*********************************************************************
559 * Converts a large unsigned integer to a string.
565 * - Converts value to a '\0' terminated string which is copied to str.
566 * - The maximum length of the copied str is 65 bytes.
567 * - Does not check if radix is in the range of 2 to 36.
568 * - If str is NULL it crashes, as the native function does.
570 char * __cdecl
_ui64toa(
571 ULONGLONG value
, /* [I] Value to be converted */
572 char *str
, /* [O] Destination for the converted value */
573 int radix
) /* [I] Number base for conversion */
583 digit
= value
% radix
;
584 value
= value
/ radix
;
586 *--pos
= '0' + digit
;
588 *--pos
= 'a' + digit
- 10;
590 } while (value
!= 0L);
592 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
597 /*********************************************************************
600 * Converts a large integer to a string.
606 * - Converts value to a Nul terminated string which is copied to str.
607 * - The maximum length of the copied str is 65 bytes. If radix
608 * is 10 and value is negative, the value is converted with sign.
609 * - Does not check if radix is in the range of 2 to 36.
610 * - If str is NULL it crashes, as the native function does.
613 * - The native DLL converts negative values (for base 10) wrong:
614 *| -1 is converted to -18446744073709551615
615 *| -2 is converted to -18446744073709551614
616 *| -9223372036854775807 is converted to -9223372036854775809
617 *| -9223372036854775808 is converted to -9223372036854775808
618 * The native msvcrt _i64toa function and our ntdll _i64toa function
619 * do not have this bug.
621 char * __cdecl
_i64toa(
622 LONGLONG value
, /* [I] Value to be converted */
623 char *str
, /* [O] Destination for the converted value */
624 int radix
) /* [I] Number base for conversion */
632 if (value
< 0 && radix
== 10) {
647 *--pos
= '0' + digit
;
649 *--pos
= 'a' + digit
- 10;
657 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
662 /*********************************************************************
665 * Convert a string to a large integer.
668 * str [I] String to be converted
671 * Success: The integer value represented by str.
672 * Failure: 0. Note that this cannot be distinguished from a successful
673 * return, if the string contains "0".
676 * - Accepts: {whitespace} [+|-] {digits}
677 * - No check is made for value overflow, only the lower 64 bits are assigned.
678 * - If str is NULL it crashes, as the native function does.
680 LONGLONG __cdecl
_atoi64( const char *str
)
682 ULONGLONG RunningTotal
= 0;
685 while (*str
== ' ' || (*str
>= '\011' && *str
<= '\015')) {
691 } else if (*str
== '-') {
696 while (*str
>= '0' && *str
<= '9') {
697 RunningTotal
= RunningTotal
* 10 + *str
- '0';
701 return bMinus
? -RunningTotal
: RunningTotal
;
705 /*********************************************************************
708 int __cdecl
NTDLL_atoi( const char *nptr
)
710 return _atoi64( nptr
);
714 /*********************************************************************
717 LONG __cdecl
NTDLL_atol( const char *nptr
)
719 return _atoi64( nptr
);
723 /*********************************************************************
726 int __cdecl
NTDLL_sscanf( const char *str
, const char *format
, ... )
730 va_start( valist
, format
);
731 ret
= vsscanf( str
, format
, valist
);
737 /*********************************************************************
738 * _splitpath (NTDLL.@)
740 * Split a path into its component pieces.
743 * inpath [I] Path to split
744 * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
745 * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
746 * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
747 * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
752 void __cdecl
_splitpath(const char* inpath
, char * drv
, char * dir
,
753 char* fname
, char * ext
)
757 if (inpath
[0] && inpath
[1] == ':')
767 else if (drv
) drv
[0] = 0;
769 /* look for end of directory part */
771 for (p
= inpath
; *p
; p
++) if (*p
== '/' || *p
== '\\') end
= p
+ 1;
773 if (end
) /* got a directory */
777 memcpy( dir
, inpath
, end
- inpath
);
778 dir
[end
- inpath
] = 0;
782 else if (dir
) dir
[0] = 0;
784 /* look for extension: what's after the last dot */
786 for (p
= inpath
; *p
; p
++) if (*p
== '.') end
= p
;
788 if (!end
) end
= p
; /* there's no extension */
792 memcpy( fname
, inpath
, end
- inpath
);
793 fname
[end
- inpath
] = 0;
795 if (ext
) strcpy( ext
, end
);