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 char * __cdecl
NTDLL_strcat( char *dst
, const char *src
)
90 return strcat( dst
, src
);
94 /*********************************************************************
97 char * __cdecl
NTDLL_strchr( const char *str
, int c
)
99 return strchr( str
, c
);
103 /*********************************************************************
106 int __cdecl
NTDLL_strcmp( const char *str1
, const char *str2
)
108 return strcmp( str1
, str2
);
112 /*********************************************************************
115 char * __cdecl
NTDLL_strcpy( char *dst
, const char *src
)
117 return strcpy( dst
, src
);
121 /*********************************************************************
124 size_t __cdecl
NTDLL_strcspn( const char *str
, const char *reject
)
126 return strcspn( str
, reject
);
130 /*********************************************************************
133 size_t __cdecl
NTDLL_strlen( const char *str
)
135 return strlen( str
);
139 /*********************************************************************
142 char * __cdecl
NTDLL_strncat( char *dst
, const char *src
, size_t len
)
144 return strncat( dst
, src
, len
);
148 /*********************************************************************
151 int __cdecl
NTDLL_strncmp( const char *str1
, const char *str2
, size_t len
)
153 return strncmp( str1
, str2
, len
);
157 /*********************************************************************
160 char * __cdecl
NTDLL_strncpy( char *dst
, const char *src
, size_t len
)
162 return strncpy( dst
, src
, len
);
166 /*********************************************************************
169 char * __cdecl
NTDLL_strpbrk( const char *str
, const char *accept
)
171 return strpbrk( str
, accept
);
175 /*********************************************************************
178 char * __cdecl
NTDLL_strrchr( const char *str
, int c
)
180 return strrchr( str
, c
);
184 /*********************************************************************
187 size_t __cdecl
NTDLL_strspn( const char *str
, const char *accept
)
189 return strspn( str
, accept
);
193 /*********************************************************************
196 char * __cdecl
NTDLL_strstr( const char *haystack
, const char *needle
)
198 return strstr( haystack
, needle
);
202 /*********************************************************************
205 void * __cdecl
_memccpy( void *dst
, const void *src
, int c
, size_t n
)
207 return memccpy( dst
, src
, c
, n
);
211 /*********************************************************************
214 * Compare two blocks of memory as strings, ignoring case.
217 * s1 [I] First string to compare to s2
218 * s2 [I] Second string to compare to s1
219 * len [I] Number of bytes to compare
222 * An integer less than, equal to, or greater than zero indicating that
223 * s1 is less than, equal to or greater than s2 respectively.
226 * Any Nul characters in s1 or s2 are ignored. This function always
227 * compares up to len bytes or the first place where s1 and s2 differ.
229 INT __cdecl
_memicmp( LPCSTR s1
, LPCSTR s2
, DWORD len
)
234 if ((ret
= tolower(*s1
) - tolower(*s2
))) break;
242 /*********************************************************************
246 int __cdecl
_stricmp( LPCSTR str1
, LPCSTR str2
)
248 return strcasecmp( str1
, str2
);
252 /*********************************************************************
253 * _strnicmp (NTDLL.@)
255 int __cdecl
_strnicmp( LPCSTR str1
, LPCSTR str2
, size_t n
)
257 return strncasecmp( str1
, str2
, n
);
261 /*********************************************************************
264 * Convert a string to upper case.
267 * str [I/O] String to convert
270 * str. There is no error return, if str is NULL or invalid, this
271 * function will crash.
273 LPSTR __cdecl
_strupr( LPSTR str
)
276 for ( ; *str
; str
++) *str
= toupper(*str
);
281 /*********************************************************************
284 * Convert a string to lowercase
287 * str [I/O] String to convert
290 * str. There is no error return, if str is NULL or invalid, this
291 * function will crash.
293 LPSTR __cdecl
_strlwr( LPSTR str
)
296 for ( ; *str
; str
++) *str
= tolower(*str
);
301 /*********************************************************************
304 int __cdecl
NTDLL_tolower( int c
)
310 /*********************************************************************
313 int __cdecl
NTDLL_toupper( int c
)
319 /*********************************************************************
322 int __cdecl
NTDLL_isalnum( int c
)
328 /*********************************************************************
331 int __cdecl
NTDLL_isalpha( int c
)
337 /*********************************************************************
340 int __cdecl
NTDLL_iscntrl( int c
)
346 /*********************************************************************
349 int __cdecl
NTDLL_isdigit( int c
)
355 /*********************************************************************
358 int __cdecl
NTDLL_isgraph( int c
)
364 /*********************************************************************
367 int __cdecl
NTDLL_islower( int c
)
373 /*********************************************************************
376 int __cdecl
NTDLL_isprint( int c
)
382 /*********************************************************************
385 int __cdecl
NTDLL_ispunct( int c
)
391 /*********************************************************************
394 int __cdecl
NTDLL_isspace( int c
)
400 /*********************************************************************
403 int __cdecl
NTDLL_isupper( int c
)
409 /*********************************************************************
412 int __cdecl
NTDLL_isxdigit( int c
)
414 return isxdigit( c
);
418 /*********************************************************************
421 LONG __cdecl
NTDLL_strtol( const char *nptr
, char **endptr
, int base
)
423 return strtol( nptr
, endptr
, base
);
427 /*********************************************************************
430 ULONG __cdecl
NTDLL_strtoul( const char *nptr
, char **endptr
, int base
)
432 return strtoul( nptr
, endptr
, base
);
436 /*********************************************************************
439 * Convert an unsigned long integer to a string.
445 * - Converts value to a Nul terminated string which is copied to str.
446 * - The maximum length of the copied str is 33 bytes.
447 * - Does not check if radix is in the range of 2 to 36.
448 * - If str is NULL it crashes, as the native function does.
450 char * __cdecl
_ultoa(
451 ULONG value
, /* [I] Value to be converted */
452 char *str
, /* [O] Destination for the converted value */
453 int radix
) /* [I] Number base for conversion */
463 digit
= value
% radix
;
464 value
= value
/ radix
;
466 *--pos
= '0' + digit
;
468 *--pos
= 'a' + digit
- 10;
470 } while (value
!= 0L);
472 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
477 /*********************************************************************
480 * Convert a long integer to a string.
486 * - Converts value to a Nul terminated string which is copied to str.
487 * - The maximum length of the copied str is 33 bytes. If radix
488 * is 10 and value is negative, the value is converted with sign.
489 * - Does not check if radix is in the range of 2 to 36.
490 * - If str is NULL it crashes, as the native function does.
492 char * __cdecl
_ltoa(
493 LONG value
, /* [I] Value to be converted */
494 char *str
, /* [O] Destination for the converted value */
495 int radix
) /* [I] Number base for conversion */
503 if (value
< 0 && radix
== 10) {
518 *--pos
= '0' + digit
;
520 *--pos
= 'a' + digit
- 10;
528 memcpy(str
, pos
, &buffer
[32] - pos
+ 1);
533 /*********************************************************************
536 * Converts an integer to a string.
542 * - Converts value to a '\0' terminated string which is copied to str.
543 * - The maximum length of the copied str is 33 bytes. If radix
544 * is 10 and value is negative, the value is converted with sign.
545 * - Does not check if radix is in the range of 2 to 36.
546 * - If str is NULL it crashes, as the native function does.
548 char * __cdecl
_itoa(
549 int value
, /* [I] Value to be converted */
550 char *str
, /* [O] Destination for the converted value */
551 int radix
) /* [I] Number base for conversion */
553 return _ltoa(value
, str
, radix
);
557 /*********************************************************************
560 * Converts a large unsigned integer to a string.
566 * - Converts value to a '\0' terminated string which is copied to str.
567 * - The maximum length of the copied str is 65 bytes.
568 * - Does not check if radix is in the range of 2 to 36.
569 * - If str is NULL it crashes, as the native function does.
571 char * __cdecl
_ui64toa(
572 ULONGLONG value
, /* [I] Value to be converted */
573 char *str
, /* [O] Destination for the converted value */
574 int radix
) /* [I] Number base for conversion */
584 digit
= value
% radix
;
585 value
= value
/ radix
;
587 *--pos
= '0' + digit
;
589 *--pos
= 'a' + digit
- 10;
591 } while (value
!= 0L);
593 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
598 /*********************************************************************
601 * Converts a large integer to a string.
607 * - Converts value to a Nul terminated string which is copied to str.
608 * - The maximum length of the copied str is 65 bytes. If radix
609 * is 10 and value is negative, the value is converted with sign.
610 * - Does not check if radix is in the range of 2 to 36.
611 * - If str is NULL it crashes, as the native function does.
614 * - The native DLL converts negative values (for base 10) wrong:
615 *| -1 is converted to -18446744073709551615
616 *| -2 is converted to -18446744073709551614
617 *| -9223372036854775807 is converted to -9223372036854775809
618 *| -9223372036854775808 is converted to -9223372036854775808
619 * The native msvcrt _i64toa function and our ntdll _i64toa function
620 * do not have this bug.
622 char * __cdecl
_i64toa(
623 LONGLONG value
, /* [I] Value to be converted */
624 char *str
, /* [O] Destination for the converted value */
625 int radix
) /* [I] Number base for conversion */
633 if (value
< 0 && radix
== 10) {
648 *--pos
= '0' + digit
;
650 *--pos
= 'a' + digit
- 10;
658 memcpy(str
, pos
, &buffer
[64] - pos
+ 1);
663 /*********************************************************************
666 * Convert a string to a large integer.
669 * str [I] String to be converted
672 * Success: The integer value represented by str.
673 * Failure: 0. Note that this cannot be distinguished from a successful
674 * return, if the string contains "0".
677 * - Accepts: {whitespace} [+|-] {digits}
678 * - No check is made for value overflow, only the lower 64 bits are assigned.
679 * - If str is NULL it crashes, as the native function does.
681 LONGLONG __cdecl
_atoi64( const char *str
)
683 ULONGLONG RunningTotal
= 0;
686 while (*str
== ' ' || (*str
>= '\011' && *str
<= '\015')) {
692 } else if (*str
== '-') {
697 while (*str
>= '0' && *str
<= '9') {
698 RunningTotal
= RunningTotal
* 10 + *str
- '0';
702 return bMinus
? -RunningTotal
: RunningTotal
;
706 /*********************************************************************
709 int __cdecl
NTDLL_atoi( const char *nptr
)
711 return _atoi64( nptr
);
715 /*********************************************************************
718 LONG __cdecl
NTDLL_atol( const char *nptr
)
720 return _atoi64( nptr
);
724 /*********************************************************************
727 int __cdecl
NTDLL_sscanf( const char *str
, const char *format
, ... )
731 va_start( valist
, format
);
732 ret
= vsscanf( str
, format
, valist
);
738 /*********************************************************************
739 * _splitpath (NTDLL.@)
741 * Split a path into its component pieces.
744 * inpath [I] Path to split
745 * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
746 * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
747 * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
748 * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
753 void __cdecl
_splitpath(const char* inpath
, char * drv
, char * dir
,
754 char* fname
, char * ext
)
758 if (inpath
[0] && inpath
[1] == ':')
768 else if (drv
) drv
[0] = 0;
770 /* look for end of directory part */
772 for (p
= inpath
; *p
; p
++) if (*p
== '/' || *p
== '\\') end
= p
+ 1;
774 if (end
) /* got a directory */
778 memcpy( dir
, inpath
, end
- inpath
);
779 dir
[end
- inpath
] = 0;
783 else if (dir
) dir
[0] = 0;
785 /* look for extension: what's after the last dot */
787 for (p
= inpath
; *p
; p
++) if (*p
== '.') end
= p
;
789 if (!end
) end
= p
; /* there's no extension */
793 memcpy( fname
, inpath
, end
- inpath
);
794 fname
[end
- inpath
] = 0;
796 if (ext
) strcpy( ext
, end
);