2000-06-23 18:16:30 +02:00
|
|
|
/*
|
|
|
|
* NTDLL string functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2001-01-22 03:17:29 +01:00
|
|
|
* Copyright 2000 Jon Griffiths
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
* Copyright 2003 Thomas Mertes
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-19 21:26:44 +02:00
|
|
|
#include <limits.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2006-04-18 20:30:43 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2000-06-23 18:16:30 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2020-06-29 10:42:28 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
#include "winternl.h"
|
2020-06-29 10:43:42 +02:00
|
|
|
#include "ntdll_misc.h"
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
|
2000-06-23 18:16:30 +02:00
|
|
|
|
2020-06-29 10:42:28 +02:00
|
|
|
/* same as wctypes except for TAB, which doesn't have C1_BLANK for some reason... */
|
|
|
|
static const unsigned short ctypes[257] =
|
|
|
|
{
|
|
|
|
/* -1 */
|
|
|
|
0x0000,
|
|
|
|
/* 00 */
|
|
|
|
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
|
|
|
|
0x0020, 0x0028, 0x0028, 0x0028, 0x0028, 0x0028, 0x0020, 0x0020,
|
|
|
|
/* 10 */
|
|
|
|
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
|
|
|
|
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
|
|
|
|
/* 20 */
|
|
|
|
0x0048, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
|
|
|
|
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
|
|
|
|
/* 30 */
|
|
|
|
0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084, 0x0084,
|
|
|
|
0x0084, 0x0084, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
|
|
|
|
/* 40 */
|
|
|
|
0x0010, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0181, 0x0101,
|
|
|
|
0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
|
|
|
|
/* 50 */
|
|
|
|
0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101,
|
|
|
|
0x0101, 0x0101, 0x0101, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
|
|
|
|
/* 60 */
|
|
|
|
0x0010, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0182, 0x0102,
|
|
|
|
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
|
|
|
|
/* 70 */
|
|
|
|
0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102, 0x0102,
|
|
|
|
0x0102, 0x0102, 0x0102, 0x0010, 0x0010, 0x0010, 0x0010, 0x0020
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-18 20:30:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* memchr (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
void * __cdecl memchr( const void *ptr, int c, size_t n )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const unsigned char *p = ptr;
|
|
|
|
|
|
|
|
for (p = ptr; n; n--, p++) if (*p == c) return (void *)(ULONG_PTR)p;
|
|
|
|
return NULL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* memcmp (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int __cdecl memcmp( const void *ptr1, const void *ptr2, size_t n )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const unsigned char *p1, *p2;
|
|
|
|
|
|
|
|
for (p1 = ptr1, p2 = ptr2; n; n--, p1++, p2++)
|
|
|
|
{
|
|
|
|
if (*p1 < *p2) return -1;
|
|
|
|
if (*p1 > *p2) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* memcpy (NTDLL.@)
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Behaves like memmove.
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
void * __cdecl memcpy( void *dst, const void *src, size_t n )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
volatile unsigned char *d = dst; /* avoid gcc optimizations */
|
|
|
|
const unsigned char *s = src;
|
|
|
|
|
|
|
|
if ((size_t)dst - (size_t)src >= n)
|
|
|
|
{
|
|
|
|
while (n--) *d++ = *s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d += n - 1;
|
|
|
|
s += n - 1;
|
|
|
|
while (n--) *d-- = *s--;
|
|
|
|
}
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* memmove (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
void * __cdecl memmove( void *dst, const void *src, size_t n )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
volatile unsigned char *d = dst; /* avoid gcc optimizations */
|
|
|
|
const unsigned char *s = src;
|
|
|
|
|
|
|
|
if ((size_t)dst - (size_t)src >= n)
|
|
|
|
{
|
|
|
|
while (n--) *d++ = *s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d += n - 1;
|
|
|
|
s += n - 1;
|
|
|
|
while (n--) *d-- = *s--;
|
|
|
|
}
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* memset (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
void * __cdecl memset( void *dst, int c, size_t n )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
volatile unsigned char *d = dst; /* avoid gcc optimizations */
|
|
|
|
while (n--) *d++ = c;
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strcat (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strcat( char *dst, const char *src )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
char *d = dst;
|
|
|
|
while (*d) d++;
|
|
|
|
while ((*d++ = *src++));
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strchr (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strchr( const char *str, int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
do { if (*str == (char)c) return (char *)(ULONG_PTR)str; } while (*str++);
|
|
|
|
return NULL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strcmp (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl strcmp( const char *str1, const char *str2 )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
while (*str1 && *str1 == *str2) { str1++; str2++; }
|
|
|
|
if ((unsigned char)*str1 > (unsigned char)*str2) return 1;
|
|
|
|
if ((unsigned char)*str1 < (unsigned char)*str2) return -1;
|
|
|
|
return 0;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strcpy (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strcpy( char *dst, const char *src )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
char *d = dst;
|
|
|
|
while ((*d++ = *src++));
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strcspn (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
size_t __cdecl strcspn( const char *str, const char *reject )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const char *ptr;
|
|
|
|
for (ptr = str; *ptr; ptr++) if (strchr( reject, *ptr )) break;
|
|
|
|
return ptr - str;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strlen (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
size_t __cdecl strlen( const char *str )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const char *s = str;
|
|
|
|
while (*s) s++;
|
|
|
|
return s - str;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strncat (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strncat( char *dst, const char *src, size_t len )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
char *d = dst;
|
|
|
|
while (*d) d++;
|
|
|
|
for ( ; len && *src; d++, src++, len--) *d = *src;
|
|
|
|
*d = 0;
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strncmp (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl strncmp( const char *str1, const char *str2, size_t len )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
if (!len) return 0;
|
|
|
|
while (--len && *str1 && *str1 == *str2) { str1++; str2++; }
|
|
|
|
return (unsigned char)*str1 - (unsigned char)*str2;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strncpy (NTDLL.@)
|
|
|
|
*/
|
2020-06-29 10:42:28 +02:00
|
|
|
#undef strncpy
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strncpy( char *dst, const char *src, size_t len )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
char *d;
|
|
|
|
for (d = dst; len && *src; d++, src++, len--) *d = *src;
|
|
|
|
while (len--) *d++ = 0;
|
|
|
|
return dst;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-18 19:19:28 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* strnlen (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
size_t __cdecl strnlen( const char *str, size_t len )
|
2018-01-18 19:19:28 +01:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const char *s = str;
|
|
|
|
for (s = str; len && *s; s++, len--) ;
|
|
|
|
return s - str;
|
2018-01-18 19:19:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 20:30:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strpbrk (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strpbrk( const char *str, const char *accept )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
for ( ; *str; str++) if (strchr( accept, *str )) return (char *)(ULONG_PTR)str;
|
|
|
|
return NULL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strrchr (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strrchr( const char *str, int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
char *ret = NULL;
|
|
|
|
do { if (*str == (char)c) ret = (char *)(ULONG_PTR)str; } while (*str++);
|
|
|
|
return ret;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strspn (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
size_t __cdecl strspn( const char *str, const char *accept )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const char *ptr;
|
|
|
|
for (ptr = str; *ptr; ptr++) if (!strchr( accept, *ptr )) break;
|
|
|
|
return ptr - str;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strstr (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
char * __cdecl strstr( const char *str, const char *sub )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
const char *p1 = str, *p2 = sub;
|
|
|
|
while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
|
|
|
|
if (!*p2) return (char *)str;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _memccpy (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void * __cdecl _memccpy( void *dst, const void *src, int c, size_t n )
|
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
unsigned char *d = dst;
|
|
|
|
const unsigned char *s = src;
|
|
|
|
while (n--) if ((*d++ = *s++) == (unsigned char)c) return d;
|
|
|
|
return NULL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-26 10:26:12 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* tolower (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl tolower( int c )
|
2019-03-26 10:26:12 +01:00
|
|
|
{
|
|
|
|
return (char)c >= 'A' && (char)c <= 'Z' ? c - 'A' + 'a' : c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 18:16:30 +02:00
|
|
|
/*********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* _memicmp (NTDLL.@)
|
2004-09-13 20:04:31 +02:00
|
|
|
*
|
|
|
|
* Compare two blocks of memory as strings, ignoring case.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* s1 [I] First string to compare to s2
|
|
|
|
* s2 [I] Second string to compare to s1
|
|
|
|
* len [I] Number of bytes to compare
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* An integer less than, equal to, or greater than zero indicating that
|
|
|
|
* s1 is less than, equal to or greater than s2 respectively.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Any Nul characters in s1 or s2 are ignored. This function always
|
|
|
|
* compares up to len bytes or the first place where s1 and s2 differ.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
2020-06-29 10:43:42 +02:00
|
|
|
int __cdecl _memicmp( const void *str1, const void *str2, size_t len )
|
2000-06-23 18:16:30 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
const unsigned char *s1 = str1, *s2 = str2;
|
2000-06-23 18:16:30 +02:00
|
|
|
int ret = 0;
|
|
|
|
while (len--)
|
|
|
|
{
|
2020-06-30 12:06:01 +02:00
|
|
|
if ((ret = tolower(*s1) - tolower(*s2))) break;
|
2000-06-23 18:16:30 +02:00
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
|
2006-01-24 12:28:34 +01:00
|
|
|
/*********************************************************************
|
2019-03-26 10:26:36 +01:00
|
|
|
* _strnicmp (NTDLL.@)
|
2006-01-24 12:28:34 +01:00
|
|
|
*/
|
2019-03-26 10:26:36 +01:00
|
|
|
int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
|
2006-01-24 12:28:34 +01:00
|
|
|
{
|
2019-03-26 10:26:36 +01:00
|
|
|
int l1, l2;
|
|
|
|
|
|
|
|
while (n--)
|
|
|
|
{
|
2020-06-30 12:06:01 +02:00
|
|
|
l1 = (unsigned char)tolower(*str1);
|
|
|
|
l2 = (unsigned char)tolower(*str2);
|
2019-03-26 10:26:36 +01:00
|
|
|
if (l1 != l2)
|
|
|
|
{
|
|
|
|
if (sizeof(void *) > sizeof(int)) return l1 - l2;
|
|
|
|
return l1 - l2 > 0 ? 1 : -1;
|
|
|
|
}
|
|
|
|
if (!l1) return 0;
|
|
|
|
str1++;
|
|
|
|
str2++;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
2019-03-26 10:26:36 +01:00
|
|
|
* _stricmp (NTDLL.@)
|
|
|
|
* _strcmpi (NTDLL.@)
|
2006-04-18 20:30:43 +02:00
|
|
|
*/
|
2019-03-26 10:26:36 +01:00
|
|
|
int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2019-03-26 10:26:36 +01:00
|
|
|
return _strnicmp( str1, str2, -1 );
|
2006-01-24 12:28:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 18:16:30 +02:00
|
|
|
/*********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* _strupr (NTDLL.@)
|
2004-09-13 20:04:31 +02:00
|
|
|
*
|
|
|
|
* Convert a string to upper case.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* str [I/O] String to convert
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* str. There is no error return, if str is NULL or invalid, this
|
|
|
|
* function will crash.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
|
|
|
LPSTR __cdecl _strupr( LPSTR str )
|
|
|
|
{
|
|
|
|
LPSTR ret = str;
|
2019-03-27 14:08:02 +01:00
|
|
|
for ( ; *str; str++) *str = RtlUpperChar(*str);
|
2000-06-23 18:16:30 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
|
2000-06-23 18:16:30 +02:00
|
|
|
/*********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* _strlwr (NTDLL.@)
|
2000-06-23 18:16:30 +02:00
|
|
|
*
|
2004-09-13 20:04:31 +02:00
|
|
|
* Convert a string to lowercase
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* str [I/O] String to convert
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* str. There is no error return, if str is NULL or invalid, this
|
|
|
|
* function will crash.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
|
|
|
LPSTR __cdecl _strlwr( LPSTR str )
|
|
|
|
{
|
|
|
|
LPSTR ret = str;
|
2020-06-30 12:06:01 +02:00
|
|
|
for ( ; *str; str++) *str = tolower(*str);
|
2000-06-23 18:16:30 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 20:30:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* toupper (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl toupper( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2019-03-26 10:26:16 +01:00
|
|
|
char str[2], *p = str;
|
|
|
|
WCHAR wc;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
str[0] = c;
|
|
|
|
str[1] = c >> 8;
|
|
|
|
wc = RtlAnsiCharToUnicodeChar( &p );
|
|
|
|
wc = RtlUpcaseUnicodeChar( wc );
|
|
|
|
RtlUnicodeToMultiByteN( str, sizeof(str), &len, &wc, sizeof(wc) );
|
|
|
|
if (len == 2) return ((unsigned char)str[0] << 8) + (unsigned char)str[1];
|
|
|
|
return (unsigned char)str[0];
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isalnum (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isalnum( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & (C1_LOWER | C1_UPPER | C1_DIGIT);
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isalpha (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isalpha( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & (C1_LOWER | C1_UPPER);
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* iscntrl (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl iscntrl( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_CNTRL;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isdigit (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isdigit( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_DIGIT;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isgraph (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isgraph( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & (C1_LOWER | C1_UPPER | C1_DIGIT | C1_PUNCT);
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* islower (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl islower( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_LOWER;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isprint (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isprint( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & (C1_LOWER | C1_UPPER | C1_DIGIT | C1_PUNCT | C1_BLANK);
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ispunct (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl ispunct( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_PUNCT;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isspace (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isspace( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_SPACE;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isupper (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isupper( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_UPPER;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* isxdigit (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl isxdigit( int c )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:42:28 +02:00
|
|
|
return ctypes[c + 1] & C1_XDIGIT;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-14 13:53:46 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __isascii (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL __isascii(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
|
|
|
return (unsigned)c < 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __toascii (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL __toascii(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
|
|
|
return (unsigned)c & 0x7f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __iscsym (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL __iscsym(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
2020-06-30 12:06:01 +02:00
|
|
|
return (c < 127 && (isalnum(c) || c == '_'));
|
2013-03-14 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __iscsymf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL __iscsymf(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
2020-06-30 12:06:01 +02:00
|
|
|
return (c < 127 && (isalpha(c) || c == '_'));
|
2013-03-14 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _toupper (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL _toupper(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
|
|
|
return c - 0x20; /* sic */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _tolower (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int CDECL _tolower(int c)
|
2013-03-14 13:53:46 +01:00
|
|
|
{
|
|
|
|
return c + 0x20; /* sic */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-29 10:43:42 +02:00
|
|
|
static int char_to_int( char c )
|
|
|
|
{
|
|
|
|
if ('0' <= c && c <= '9') return c - '0';
|
|
|
|
if ('A' <= c && c <= 'Z') return c - 'A' + 10;
|
|
|
|
if ('a' <= c && c <= 'z') return c - 'a' + 10;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-18 20:30:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* strtol (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
__msvcrt_long __cdecl strtol( const char *s, char **end, int base )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
BOOL negative = FALSE, empty = TRUE;
|
|
|
|
LONG ret = 0;
|
|
|
|
|
|
|
|
if (base < 0 || base == 1 || base > 36) return 0;
|
|
|
|
if (end) *end = (char *)s;
|
2020-06-30 12:06:01 +02:00
|
|
|
while (isspace(*s)) s++;
|
2020-06-29 10:43:42 +02:00
|
|
|
|
|
|
|
if (*s == '-')
|
|
|
|
{
|
|
|
|
negative = TRUE;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else if (*s == '+') s++;
|
|
|
|
|
|
|
|
if ((base == 0 || base == 16) && !char_to_int( *s ) && (s[1] == 'x' || s[1] == 'X'))
|
|
|
|
{
|
|
|
|
base = 16;
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
if (base == 0) base = char_to_int( *s ) ? 10 : 8;
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
int v = char_to_int( *s );
|
|
|
|
if (v < 0 || v >= base) break;
|
|
|
|
if (negative) v = -v;
|
|
|
|
s++;
|
|
|
|
empty = FALSE;
|
|
|
|
|
|
|
|
if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
|
|
|
|
ret = MAXLONG;
|
|
|
|
else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
|
|
|
|
ret = MINLONG;
|
|
|
|
else
|
|
|
|
ret = ret * base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end && !empty) *end = (char *)s;
|
|
|
|
return ret;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* strtoul (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
__msvcrt_ulong __cdecl strtoul( const char *s, char **end, int base )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
2020-06-29 10:43:42 +02:00
|
|
|
BOOL negative = FALSE, empty = TRUE;
|
|
|
|
ULONG ret = 0;
|
|
|
|
|
|
|
|
if (base < 0 || base == 1 || base > 36) return 0;
|
|
|
|
if (end) *end = (char *)s;
|
2020-06-30 12:06:01 +02:00
|
|
|
while (isspace(*s)) s++;
|
2020-06-29 10:43:42 +02:00
|
|
|
|
|
|
|
if (*s == '-')
|
|
|
|
{
|
|
|
|
negative = TRUE;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else if (*s == '+') s++;
|
|
|
|
|
|
|
|
if ((base == 0 || base == 16) && !char_to_int( *s ) && (s[1] == 'x' || s[1] == 'X'))
|
|
|
|
{
|
|
|
|
base = 16;
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
if (base == 0) base = char_to_int( *s ) ? 10 : 8;
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
int v = char_to_int( *s );
|
|
|
|
if (v < 0 || v >= base) break;
|
|
|
|
s++;
|
|
|
|
empty = FALSE;
|
|
|
|
|
|
|
|
if (ret > MAXDWORD / base || ret * base > MAXDWORD - v)
|
|
|
|
ret = MAXDWORD;
|
|
|
|
else
|
|
|
|
ret = ret * base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end && !empty) *end = (char *)s;
|
|
|
|
return negative ? -ret : ret;
|
2006-04-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-23 18:16:30 +02:00
|
|
|
/*********************************************************************
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
* _ultoa (NTDLL.@)
|
|
|
|
*
|
2004-09-13 20:04:31 +02:00
|
|
|
* Convert an unsigned long integer to a string.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str.
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Converts value to a Nul terminated string which is copied to str.
|
|
|
|
* - The maximum length of the copied str is 33 bytes.
|
|
|
|
* - Does not check if radix is in the range of 2 to 36.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
char * __cdecl _ultoa( __msvcrt_ulong value, char *str, int radix )
|
2000-06-23 18:16:30 +02:00
|
|
|
{
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
char buffer[33];
|
|
|
|
char *pos;
|
|
|
|
int digit;
|
2000-06-23 18:16:30 +02:00
|
|
|
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
pos = &buffer[32];
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = value % radix;
|
|
|
|
value = value / radix;
|
|
|
|
if (digit < 10) {
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
} else {
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
} /* if */
|
|
|
|
} while (value != 0L);
|
|
|
|
|
|
|
|
memcpy(str, pos, &buffer[32] - pos + 1);
|
|
|
|
return str;
|
2000-06-23 18:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
* _ltoa (NTDLL.@)
|
|
|
|
*
|
2004-09-13 20:04:31 +02:00
|
|
|
* Convert a long integer to a string.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str.
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Converts value to a Nul terminated string which is copied to str.
|
|
|
|
* - The maximum length of the copied str is 33 bytes. If radix
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* is 10 and value is negative, the value is converted with sign.
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Does not check if radix is in the range of 2 to 36.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
char * __cdecl _ltoa( __msvcrt_long value, char *str, int radix )
|
2000-06-23 18:16:30 +02:00
|
|
|
{
|
2007-06-11 13:13:32 +02:00
|
|
|
ULONG val;
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
int negative;
|
|
|
|
char buffer[33];
|
|
|
|
char *pos;
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10) {
|
|
|
|
negative = 1;
|
|
|
|
val = -value;
|
|
|
|
} else {
|
|
|
|
negative = 0;
|
|
|
|
val = value;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
pos = &buffer[32];
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = val % radix;
|
|
|
|
val = val / radix;
|
|
|
|
if (digit < 10) {
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
} else {
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
} /* if */
|
|
|
|
} while (val != 0L);
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
*--pos = '-';
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
memcpy(str, pos, &buffer[32] - pos + 1);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _itoa (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Converts an integer to a string.
|
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str.
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Converts value to a '\0' terminated string which is copied to str.
|
|
|
|
* - The maximum length of the copied str is 33 bytes. If radix
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* is 10 and value is negative, the value is converted with sign.
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Does not check if radix is in the range of 2 to 36.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*/
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
char * __cdecl _itoa(
|
|
|
|
int value, /* [I] Value to be converted */
|
|
|
|
char *str, /* [O] Destination for the converted value */
|
|
|
|
int radix) /* [I] Number base for conversion */
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
{
|
|
|
|
return _ltoa(value, str, radix);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ui64toa (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Converts a large unsigned integer to a string.
|
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str.
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Converts value to a '\0' terminated string which is copied to str.
|
|
|
|
* - The maximum length of the copied str is 65 bytes.
|
|
|
|
* - Does not check if radix is in the range of 2 to 36.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*/
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
char * __cdecl _ui64toa(
|
|
|
|
ULONGLONG value, /* [I] Value to be converted */
|
|
|
|
char *str, /* [O] Destination for the converted value */
|
|
|
|
int radix) /* [I] Number base for conversion */
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
{
|
|
|
|
char buffer[65];
|
|
|
|
char *pos;
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
pos = &buffer[64];
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = value % radix;
|
|
|
|
value = value / radix;
|
|
|
|
if (digit < 10) {
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
} else {
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
} /* if */
|
|
|
|
} while (value != 0L);
|
|
|
|
|
|
|
|
memcpy(str, pos, &buffer[64] - pos + 1);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _i64toa (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Converts a large integer to a string.
|
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Converts value to a Nul terminated string which is copied to str.
|
|
|
|
* - The maximum length of the copied str is 65 bytes. If radix
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* is 10 and value is negative, the value is converted with sign.
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Does not check if radix is in the range of 2 to 36.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* DIFFERENCES
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
* - The native DLL converts negative values (for base 10) wrong:
|
2004-09-13 20:04:31 +02:00
|
|
|
*| -1 is converted to -18446744073709551615
|
|
|
|
*| -2 is converted to -18446744073709551614
|
|
|
|
*| -9223372036854775807 is converted to -9223372036854775809
|
|
|
|
*| -9223372036854775808 is converted to -9223372036854775808
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* The native msvcrt _i64toa function and our ntdll _i64toa function
|
|
|
|
* do not have this bug.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*/
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
char * __cdecl _i64toa(
|
|
|
|
LONGLONG value, /* [I] Value to be converted */
|
|
|
|
char *str, /* [O] Destination for the converted value */
|
|
|
|
int radix) /* [I] Number base for conversion */
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
{
|
|
|
|
ULONGLONG val;
|
|
|
|
int negative;
|
|
|
|
char buffer[65];
|
|
|
|
char *pos;
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
if (value < 0 && radix == 10) {
|
|
|
|
negative = 1;
|
|
|
|
val = -value;
|
|
|
|
} else {
|
|
|
|
negative = 0;
|
|
|
|
val = value;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
pos = &buffer[64];
|
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
do {
|
|
|
|
digit = val % radix;
|
|
|
|
val = val / radix;
|
|
|
|
if (digit < 10) {
|
|
|
|
*--pos = '0' + digit;
|
|
|
|
} else {
|
|
|
|
*--pos = 'a' + digit - 10;
|
|
|
|
} /* if */
|
|
|
|
} while (val != 0L);
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
*--pos = '-';
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
memcpy(str, pos, &buffer[64] - pos + 1);
|
|
|
|
return str;
|
2000-06-23 18:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
* _atoi64 (NTDLL.@)
|
|
|
|
*
|
2004-09-13 20:04:31 +02:00
|
|
|
* Convert a string to a large integer.
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
*
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
* PARAMS
|
2004-09-13 20:04:31 +02:00
|
|
|
* str [I] String to be converted
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
2004-09-13 20:04:31 +02:00
|
|
|
* Success: The integer value represented by str.
|
|
|
|
* Failure: 0. Note that this cannot be distinguished from a successful
|
|
|
|
* return, if the string contains "0".
|
- Implement RtlDowncaseUnicodeString, RtlUniform, iswdigit, iswlower,
iswspace, iswxdigit.
- Fixed RtlInt64ToUnicodeString and RtlIntegerToUnicodeString.
- According to tests RtlAppendUnicodeStringToString leaves the
destination unchanged when the source length is 0 (FIXED).
- Documentation updates in RtlExtendedMagicDivide,
RtlLargeIntegerToChar, RtlInt64ToUnicodeString, RtlUpperChar,
RtlUpperString, RtlUpcaseUnicodeChar, RtlCharToInteger,
RtlIntegerToChar, RtlUnicodeStringToInteger,
RtlIntegerToUnicodeString, _ultoa, _ltoa, _itoa, _ui64toa, _i64toa,
_atoi64, _ultow, _ltow, _itow, _ui64tow, _i64tow, _wtol, _wtoi,
_wtoi64.
2003-03-22 01:20:58 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2004-09-13 20:04:31 +02:00
|
|
|
* - Accepts: {whitespace} [+|-] {digits}
|
|
|
|
* - No check is made for value overflow, only the lower 64 bits are assigned.
|
|
|
|
* - If str is NULL it crashes, as the native function does.
|
2000-06-23 18:16:30 +02:00
|
|
|
*/
|
2008-07-22 03:15:20 +02:00
|
|
|
LONGLONG __cdecl _atoi64( const char *str )
|
2000-06-23 18:16:30 +02:00
|
|
|
{
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
ULONGLONG RunningTotal = 0;
|
2013-11-01 00:21:24 +01:00
|
|
|
BOOL bMinus = FALSE;
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
|
|
|
|
while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
|
|
|
|
str++;
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
if (*str == '+') {
|
|
|
|
str++;
|
|
|
|
} else if (*str == '-') {
|
2013-11-01 00:21:24 +01:00
|
|
|
bMinus = TRUE;
|
Implement _itoa, _ltoa, _ultoa, _i64toa, _ui64toa, _itow, _ltow,
_ultow, _i64tow, _ui64tow, _atoi64, _wtoi, _wtol, _wtoi64.
2003-03-12 21:16:07 +01:00
|
|
|
str++;
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
while (*str >= '0' && *str <= '9') {
|
|
|
|
RunningTotal = RunningTotal * 10 + *str - '0';
|
|
|
|
str++;
|
|
|
|
} /* while */
|
|
|
|
|
|
|
|
return bMinus ? -RunningTotal : RunningTotal;
|
2000-06-23 18:16:30 +02:00
|
|
|
}
|
2001-01-22 03:17:29 +01:00
|
|
|
|
|
|
|
|
2008-07-22 03:15:20 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* atoi (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int __cdecl atoi( const char *nptr )
|
2008-07-22 03:15:20 +02:00
|
|
|
{
|
|
|
|
return _atoi64( nptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* atol (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
__msvcrt_long __cdecl atol( const char *nptr )
|
2008-07-22 03:15:20 +02:00
|
|
|
{
|
|
|
|
return _atoi64( nptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-19 21:26:44 +02:00
|
|
|
/* helper function for *scanf. Returns the value of character c in the
|
|
|
|
* given base, or -1 if the given character is not a digit of the base.
|
|
|
|
*/
|
|
|
|
static int char2digit( char c, int base )
|
|
|
|
{
|
|
|
|
if ((c >= '0' && c <= '9') && (c <= '0'+base-1)) return (c-'0');
|
|
|
|
if (base <= 10) return -1;
|
|
|
|
if ((c >= 'A') && (c <= 'Z') && (c <= 'A'+base-11)) return (c-'A'+10);
|
|
|
|
if ((c >= 'a') && (c <= 'z') && (c <= 'a'+base-11)) return (c-'a'+10);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-30 12:06:01 +02:00
|
|
|
static int vsscanf( const char *str, const char *format, __ms_va_list ap)
|
2015-09-19 21:26:44 +02:00
|
|
|
{
|
|
|
|
int rd = 0, consumed = 0;
|
|
|
|
int nch;
|
|
|
|
if (!*format) return 0;
|
|
|
|
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (nch == '\0')
|
|
|
|
return EOF;
|
|
|
|
|
|
|
|
while (*format)
|
|
|
|
{
|
2020-06-30 12:06:01 +02:00
|
|
|
if (isspace( *format ))
|
2015-09-19 21:26:44 +02:00
|
|
|
{
|
|
|
|
/* skip whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while ((nch != '\0') && isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
nch = (consumed++, *str++);
|
|
|
|
}
|
|
|
|
else if (*format == '%')
|
|
|
|
{
|
|
|
|
int st = 0;
|
|
|
|
BOOLEAN suppress = 0;
|
|
|
|
int width = 0;
|
|
|
|
int base;
|
|
|
|
int h_prefix = 0;
|
|
|
|
BOOLEAN l_prefix = FALSE;
|
|
|
|
BOOLEAN w_prefix = FALSE;
|
|
|
|
BOOLEAN I64_prefix = FALSE;
|
|
|
|
BOOLEAN prefix_finished = FALSE;
|
|
|
|
format++;
|
|
|
|
/* a leading asterisk means 'suppress assignment of this field' */
|
|
|
|
if (*format == '*')
|
|
|
|
{
|
|
|
|
format++;
|
|
|
|
suppress = TRUE;
|
|
|
|
}
|
|
|
|
/* look for width specification */
|
|
|
|
while (isdigit( *format ))
|
|
|
|
{
|
|
|
|
width *= 10;
|
|
|
|
width += *format++ - '0';
|
|
|
|
}
|
|
|
|
if (width == 0) width = -1; /* no width spec seen */
|
|
|
|
/* read prefix (if any) */
|
|
|
|
while (!prefix_finished)
|
|
|
|
{
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case 'h': h_prefix++; break;
|
|
|
|
case 'l':
|
|
|
|
if (*(format+1) == 'l')
|
|
|
|
{
|
|
|
|
I64_prefix = TRUE;
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
l_prefix = TRUE;
|
|
|
|
break;
|
|
|
|
case 'w': w_prefix = TRUE; break;
|
|
|
|
case 'I':
|
|
|
|
if (*(format + 1) == '6' &&
|
|
|
|
*(format + 2) == '4')
|
|
|
|
{
|
|
|
|
I64_prefix = TRUE;
|
|
|
|
format += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prefix_finished = TRUE;
|
|
|
|
}
|
|
|
|
if (!prefix_finished) format++;
|
|
|
|
}
|
|
|
|
/* read type */
|
|
|
|
switch (*format)
|
|
|
|
{
|
|
|
|
case 'p':
|
|
|
|
case 'P': /* pointer. */
|
|
|
|
if (sizeof(void *) == sizeof(LONGLONG)) I64_prefix = TRUE;
|
|
|
|
/* fall through */
|
|
|
|
case 'x':
|
|
|
|
case 'X': /* hexadecimal integer. */
|
|
|
|
base = 16;
|
|
|
|
goto number;
|
|
|
|
case 'o': /* octal integer */
|
|
|
|
base = 8;
|
|
|
|
goto number;
|
|
|
|
case 'u': /* unsigned decimal integer */
|
|
|
|
base = 10;
|
|
|
|
goto number;
|
|
|
|
case 'd': /* signed decimal integer */
|
|
|
|
base = 10;
|
|
|
|
goto number;
|
|
|
|
case 'i': /* generic integer */
|
|
|
|
base = 0;
|
|
|
|
number:
|
|
|
|
{
|
|
|
|
/* read an integer */
|
|
|
|
ULONGLONG cur = 0;
|
|
|
|
BOOLEAN negative = FALSE;
|
|
|
|
BOOLEAN seendigit = FALSE;
|
|
|
|
/* skip initial whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while ((nch != '\0') && isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
nch = (consumed++, *str++);
|
|
|
|
/* get sign */
|
|
|
|
if (nch == '-' || nch == '+')
|
|
|
|
{
|
|
|
|
negative = (nch == '-');
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
}
|
|
|
|
/* look for leading indication of base */
|
|
|
|
if (width != 0 && nch == '0' && *format != 'p' && *format != 'P')
|
|
|
|
{
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
seendigit = TRUE;
|
|
|
|
if (width != 0 && (nch == 'x' || nch == 'X'))
|
|
|
|
{
|
|
|
|
if (base == 0)
|
|
|
|
base = 16;
|
|
|
|
if (base == 16)
|
|
|
|
{
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
seendigit = FALSE;
|
|
|
|
}
|
|
|
|
} else if (base == 0)
|
|
|
|
base = 8;
|
|
|
|
}
|
|
|
|
/* format %i without indication of base */
|
|
|
|
if (base == 0)
|
|
|
|
base = 10;
|
|
|
|
/* throw away leading zeros */
|
|
|
|
while (width != 0 && nch == '0')
|
|
|
|
{
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
seendigit = TRUE;
|
|
|
|
}
|
|
|
|
if (width != 0 && char2digit( nch, base ) != -1)
|
|
|
|
{
|
|
|
|
cur = char2digit( nch, base );
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
seendigit = TRUE;
|
|
|
|
}
|
|
|
|
/* read until no more digits */
|
|
|
|
while (width != 0 && nch != '\0' && char2digit( nch, base ) != -1)
|
|
|
|
{
|
|
|
|
cur = cur*base + char2digit( nch, base );
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
seendigit = TRUE;
|
|
|
|
}
|
|
|
|
/* okay, done! */
|
|
|
|
if (!seendigit) break; /* not a valid number */
|
|
|
|
st = 1;
|
|
|
|
if (!suppress)
|
|
|
|
{
|
|
|
|
#define _SET_NUMBER_( type ) *va_arg( ap, type* ) = negative ? -cur : cur
|
|
|
|
if (I64_prefix) _SET_NUMBER_( LONGLONG );
|
|
|
|
else if (l_prefix) _SET_NUMBER_( LONG );
|
|
|
|
else if (h_prefix == 1) _SET_NUMBER_( short int );
|
|
|
|
else _SET_NUMBER_( int );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* According to msdn,
|
|
|
|
* 's' reads a character string in a call to fscanf
|
|
|
|
* and 'S' a wide character string and vice versa in a
|
|
|
|
* call to fwscanf. The 'h', 'w' and 'l' prefixes override
|
|
|
|
* this behaviour. 'h' forces reading char * but 'l' and 'w'
|
|
|
|
* force reading WCHAR. */
|
|
|
|
case 's':
|
|
|
|
if (w_prefix || l_prefix) goto widecharstring;
|
|
|
|
else if (h_prefix) goto charstring;
|
|
|
|
else goto charstring;
|
|
|
|
case 'S':
|
|
|
|
if (w_prefix || l_prefix) goto widecharstring;
|
|
|
|
else if (h_prefix) goto charstring;
|
|
|
|
else goto widecharstring;
|
|
|
|
charstring:
|
|
|
|
{ /* read a word into a char */
|
|
|
|
char *sptr = suppress ? NULL : va_arg( ap, char * );
|
|
|
|
char *sptr_beg = sptr;
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
/* skip initial whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while (nch != '\0' && isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
nch = (consumed++, *str++);
|
|
|
|
/* read until whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while (width != 0 && nch != '\0' && !isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
{
|
|
|
|
if (!suppress)
|
|
|
|
{
|
|
|
|
*sptr++ = nch;
|
|
|
|
if(size > 1) size--;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*sptr_beg = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
}
|
|
|
|
/* terminate */
|
|
|
|
if (st && !suppress) *sptr = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
widecharstring:
|
|
|
|
{ /* read a word into a WCHAR * */
|
|
|
|
WCHAR *sptr = suppress ? NULL : va_arg( ap, WCHAR * );
|
|
|
|
WCHAR *sptr_beg = sptr;
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
/* skip initial whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while (nch != '\0' && isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
nch = (consumed++, *str++);
|
|
|
|
/* read until whitespace */
|
2020-06-30 12:06:01 +02:00
|
|
|
while (width != 0 && nch != '\0' && !isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
{
|
|
|
|
if (!suppress)
|
|
|
|
{
|
|
|
|
*sptr++ = nch;
|
|
|
|
if (size > 1) size--;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*sptr_beg = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
}
|
|
|
|
/* terminate */
|
|
|
|
if (st && !suppress) *sptr = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* 'c' and 'C work analogously to 's' and 'S' as described
|
|
|
|
* above */
|
|
|
|
case 'c':
|
|
|
|
if (w_prefix || l_prefix) goto widecharacter;
|
|
|
|
else if (h_prefix) goto character;
|
|
|
|
else goto character;
|
|
|
|
case 'C':
|
|
|
|
if (w_prefix || l_prefix) goto widecharacter;
|
|
|
|
else if (h_prefix) goto character;
|
|
|
|
else goto widecharacter;
|
|
|
|
character:
|
|
|
|
{ /* read single character into char */
|
2018-01-05 16:09:30 +01:00
|
|
|
char *sptr = suppress ? NULL : va_arg( ap, char * );
|
|
|
|
char *sptr_beg = sptr;
|
2015-09-19 21:26:44 +02:00
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
if (width == -1) width = 1;
|
|
|
|
while (width && nch != '\0')
|
|
|
|
{
|
|
|
|
if (!suppress)
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
*sptr++ = nch;
|
2015-09-19 21:26:44 +02:00
|
|
|
if(size) size--;
|
|
|
|
else
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
*sptr_beg = 0;
|
2015-09-19 21:26:44 +02:00
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
width--;
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
widecharacter:
|
|
|
|
{ /* read single character into a WCHAR */
|
2018-01-05 16:09:30 +01:00
|
|
|
WCHAR *sptr = suppress ? NULL : va_arg( ap, WCHAR * );
|
|
|
|
WCHAR *sptr_beg = sptr;
|
2015-09-19 21:26:44 +02:00
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
if (width == -1) width = 1;
|
|
|
|
while (width && nch != '\0')
|
|
|
|
{
|
|
|
|
if (!suppress)
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
*sptr++ = nch;
|
2015-09-19 21:26:44 +02:00
|
|
|
if (size) size--;
|
|
|
|
else
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
*sptr_beg = 0;
|
2015-09-19 21:26:44 +02:00
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
width--;
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
{
|
|
|
|
if (!suppress)
|
|
|
|
{
|
|
|
|
int *n = va_arg( ap, int * );
|
|
|
|
*n = consumed - 1;
|
|
|
|
}
|
|
|
|
/* This is an odd one: according to the standard,
|
|
|
|
* "Execution of a %n directive does not increment the
|
|
|
|
* assignment count returned at the completion of
|
|
|
|
* execution" even if it wasn't suppressed with the
|
|
|
|
* '*' flag. The Corrigendum to the standard seems
|
|
|
|
* to contradict this (comment out the assignment to
|
|
|
|
* suppress below if you want to implement these
|
|
|
|
* alternate semantics) but the windows program I'm
|
|
|
|
* looking at expects the behavior I've coded here
|
|
|
|
* (which happens to be what glibc does as well).
|
|
|
|
*/
|
|
|
|
suppress = TRUE;
|
|
|
|
st = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '[':
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
char *sptr = suppress ? NULL : va_arg( ap, char * );
|
|
|
|
char *sptr_beg = sptr;
|
2015-09-19 21:26:44 +02:00
|
|
|
RTL_BITMAP bitMask;
|
2018-01-05 16:09:30 +01:00
|
|
|
ULONG Mask[8] = { 0 };
|
2015-09-19 21:26:44 +02:00
|
|
|
BOOLEAN invert = FALSE; /* Set if we are NOT to find the chars */
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
|
|
|
|
RtlInitializeBitMap( &bitMask, Mask, sizeof(Mask) * 8 );
|
|
|
|
|
|
|
|
/* Read the format */
|
|
|
|
format++;
|
|
|
|
if (*format == '^')
|
|
|
|
{
|
|
|
|
invert = TRUE;
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
if (*format == ']')
|
|
|
|
{
|
|
|
|
RtlSetBits( &bitMask, ']', 1 );
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
while (*format && (*format != ']'))
|
|
|
|
{
|
|
|
|
/* According to msdn:
|
|
|
|
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
|
|
|
|
if ((*format == '-') && (*(format + 1) != ']'))
|
|
|
|
{
|
|
|
|
if ((*(format - 1)) < *(format + 1))
|
|
|
|
RtlSetBits( &bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1) );
|
|
|
|
else
|
|
|
|
RtlSetBits( &bitMask, *(format + 1) , *(format - 1) - *(format + 1) );
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
RtlSetBits( &bitMask, *format, 1 );
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
/* read until char is not suitable */
|
|
|
|
while (width != 0 && nch != '\0')
|
|
|
|
{
|
|
|
|
if (!invert)
|
|
|
|
{
|
|
|
|
if(RtlAreBitsSet( &bitMask, nch, 1 ))
|
|
|
|
{
|
|
|
|
if (!suppress) *sptr++ = nch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (RtlAreBitsClear( &bitMask, nch, 1 ))
|
|
|
|
{
|
|
|
|
if (!suppress) *sptr++ = nch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (width > 0) width--;
|
|
|
|
if(size > 1) size--;
|
|
|
|
else
|
|
|
|
{
|
2018-01-05 16:09:30 +01:00
|
|
|
if (!suppress) *sptr_beg = 0;
|
2015-09-19 21:26:44 +02:00
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* terminate */
|
|
|
|
if (!suppress) *sptr = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* From spec: "if a percent sign is followed by a character
|
|
|
|
* that has no meaning as a format-control character, that
|
|
|
|
* character and the following characters are treated as
|
|
|
|
* an ordinary sequence of characters, that is, a sequence
|
|
|
|
* of characters that must match the input. For example,
|
|
|
|
* to specify that a percent-sign character is to be input,
|
|
|
|
* use %%." */
|
2020-06-30 12:06:01 +02:00
|
|
|
while (nch != '\0' && isspace( nch ))
|
2015-09-19 21:26:44 +02:00
|
|
|
nch = (consumed++, *str++);
|
|
|
|
if (nch == *format)
|
|
|
|
{
|
|
|
|
suppress = TRUE; /* whoops no field to be read */
|
|
|
|
st = 1; /* but we got what we expected */
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (st && !suppress) rd++;
|
|
|
|
else if (!st) break;
|
|
|
|
}
|
|
|
|
/* A non-white-space character causes scanf to read, but not store,
|
|
|
|
* a matching non-white-space character. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nch == *format)
|
|
|
|
nch = (consumed++, *str++);
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
if (nch != '\0')
|
|
|
|
{
|
|
|
|
consumed--, str--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-18 20:30:43 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* sscanf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:06:01 +02:00
|
|
|
int WINAPIV sscanf( const char *str, const char *format, ... )
|
2006-04-18 20:30:43 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2015-09-19 21:26:44 +02:00
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start( valist, format );
|
2020-06-30 12:06:01 +02:00
|
|
|
ret = vsscanf( str, format, valist );
|
2015-09-19 21:26:44 +02:00
|
|
|
__ms_va_end( valist );
|
2006-04-18 20:30:43 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-22 03:17:29 +01:00
|
|
|
/*********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* _splitpath (NTDLL.@)
|
2004-09-13 20:04:31 +02:00
|
|
|
*
|
|
|
|
* Split a path into its component pieces.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* inpath [I] Path to split
|
|
|
|
* drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
|
|
|
|
* dir [O] Destination for directory component. Should be at least MAX_PATH characters.
|
|
|
|
* fname [O] Destination for File name component. Should be at least MAX_PATH characters.
|
|
|
|
* ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
|
2005-11-09 11:30:57 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2001-01-22 03:17:29 +01:00
|
|
|
*/
|
|
|
|
void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
|
|
|
|
char* fname, char * ext )
|
|
|
|
{
|
2003-10-15 04:34:51 +02:00
|
|
|
const char *p, *end;
|
|
|
|
|
|
|
|
if (inpath[0] && inpath[1] == ':')
|
2001-01-22 03:17:29 +01:00
|
|
|
{
|
2003-10-15 04:34:51 +02:00
|
|
|
if (drv)
|
|
|
|
{
|
|
|
|
drv[0] = inpath[0];
|
|
|
|
drv[1] = inpath[1];
|
|
|
|
drv[2] = 0;
|
|
|
|
}
|
|
|
|
inpath += 2;
|
2001-01-22 03:17:29 +01:00
|
|
|
}
|
2003-10-15 04:34:51 +02:00
|
|
|
else if (drv) drv[0] = 0;
|
|
|
|
|
|
|
|
/* look for end of directory part */
|
|
|
|
end = NULL;
|
|
|
|
for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
|
|
|
|
|
|
|
|
if (end) /* got a directory */
|
2001-01-22 03:17:29 +01:00
|
|
|
{
|
2003-10-15 04:34:51 +02:00
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
memcpy( dir, inpath, end - inpath );
|
|
|
|
dir[end - inpath] = 0;
|
|
|
|
}
|
|
|
|
inpath = end;
|
2001-01-22 03:17:29 +01:00
|
|
|
}
|
2003-10-15 04:34:51 +02:00
|
|
|
else if (dir) dir[0] = 0;
|
|
|
|
|
2003-10-22 01:51:06 +02:00
|
|
|
/* look for extension: what's after the last dot */
|
|
|
|
end = NULL;
|
|
|
|
for (p = inpath; *p; p++) if (*p == '.') end = p;
|
|
|
|
|
|
|
|
if (!end) end = p; /* there's no extension */
|
2001-01-22 03:17:29 +01:00
|
|
|
|
|
|
|
if (fname)
|
|
|
|
{
|
2003-10-15 04:34:51 +02:00
|
|
|
memcpy( fname, inpath, end - inpath );
|
|
|
|
fname[end - inpath] = 0;
|
2001-01-22 03:17:29 +01:00
|
|
|
}
|
2003-10-15 04:34:51 +02:00
|
|
|
if (ext) strcpy( ext, end );
|
2001-01-22 03:17:29 +01:00
|
|
|
}
|