Ignore:
Timestamp:
Apr 7, 2003, 8:40:53 PM (22 years ago)
Author:
sandervl
Message:

PF: NTDLL update for GCC 3.2.1 + resync with Wine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/NTDLL/string.c

    r9684 r9986  
    2525#include <string.h>
    2626
     27
    2728#include "windef.h"
    2829
     
    3031 *                  _memicmp   (NTDLL.@)
    3132 */
    32 #ifdef __WIN32OS2__
    33 INT __cdecl NTDLL_memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
    34 #else
    35 INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
    36 #endif
     33INT __cdecl NTDLL__memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
    3734{
    3835    int ret = 0;
     
    7370 */
    7471#ifdef __WIN32OS2__
    75 LPSTR  __cdecl NTDLL_ultoa( unsigned long x, LPSTR buf, INT radix )
     72LPSTR  __cdecl NTDLL_ultoa( unsigned long value, LPSTR str, INT radix )
    7673#else
    77 LPSTR  __cdecl _ultoa( unsigned long x, LPSTR buf, INT radix )
     74LPSTR  __cdecl _ultoa( unsigned long value, LPSTR str, INT radix )
    7875#endif
    7976{
    80     char buffer[32], *p;
    81 
    82     p = buffer + sizeof(buffer);
    83     *--p = 0;
    84     do
    85     {
    86         int rem = x % radix;
    87         *--p = (rem <= 9) ? rem + '0' : rem + 'a' - 10;
    88         x /= radix;
    89     } while (x);
    90     strcpy( buf, p );
    91     return buf;
     77    char buffer[33];
     78    char *pos;
     79    int digit;
     80
     81    pos = &buffer[32];
     82    *pos = '\0';
     83
     84    do {
     85        digit = value % radix;
     86        value = value / radix;
     87        if (digit < 10) {
     88            *--pos = '0' + digit;
     89        } else {
     90            *--pos = 'a' + digit - 10;
     91        } /* if */
     92    } while (value != 0L);
     93
     94    memcpy(str, pos, &buffer[32] - pos + 1);
     95    return str;
    9296}
    9397
     
    9599/*********************************************************************
    96100 *                  _ltoa   (NTDLL.@)
    97  */
     101 *
     102 * RETURNS
     103 *  Always returns str.
     104 *
     105 * NOTES
     106 *  Converts value to a '\0' terminated string which is copied to str.
     107 *  The maximum length of the copied str is 33 bytes. If radix
     108 *  is 10 and value is negative, the value is converted with sign.
     109 *  Does not check if radix is in the range of 2 to 36.
     110 *  If str is NULL it crashes, as the native function does.
     111 */
     112
    98113#ifdef __WIN32OS2__
    99 LPSTR  __cdecl NTDLL_ltoa( long x, LPSTR buf, INT radix )
     114LPSTR  __cdecl NTDLL_ltoa( long value, LPSTR str, INT radix )
    100115#else
    101 LPSTR  __cdecl _ltoa( long x, LPSTR buf, INT radix )
     116LPSTR  __cdecl _ltoa( long value, LPSTR str, INT radix )
    102117#endif
    103118{
    104     LPSTR p = buf;
    105     if (x < 0)
    106     {
    107         *p++ = '-';
    108         x = -x;
    109     }
    110     _ultoa( x, p, radix );
    111     return buf;
     119    unsigned long val;
     120    int negative;
     121    char buffer[33];
     122    char *pos;
     123    int digit;
     124
     125    if (value < 0 && radix == 10) {
     126        negative = 1;
     127        val = -value;
     128    } else {
     129        negative = 0;
     130        val = value;
     131    } /* if */
     132
     133    pos = &buffer[32];
     134    *pos = '\0';
     135
     136    do {
     137        digit = val % radix;
     138        val = val / radix;
     139        if (digit < 10) {
     140            *--pos = '0' + digit;
     141        } else {
     142            *--pos = 'a' + digit - 10;
     143        } /* if */
     144    } while (val != 0L);
     145
     146    if (negative) {
     147        *--pos = '-';
     148    } /* if */
     149
     150    memcpy(str, pos, &buffer[32] - pos + 1);
     151    return str;
    112152}
    113153
     
    122162#endif
    123163{
    124     return _ltoa( x, buf, radix );
     164    return NTDLL_ltoa( x, buf, radix );
     165}
     166
     167/*********************************************************************
     168 *      _ui64toa   (NTDLL.@)
     169 *
     170 * Converts a large unsigned integer to a string.
     171 *
     172 * Assigns a '\0' terminated string to str and returns str.
     173 * Does not check if radix is in the range of 2 to 36 (as native DLL).
     174 * For str == NULL just crashes (as native DLL).
     175 */
     176char * __cdecl _ui64toa( ULONGLONG value, char *str, int radix )
     177{
     178    char buffer[65];
     179    char *pos;
     180    int digit;
     181
     182    pos = &buffer[64];
     183    *pos = '\0';
     184
     185    do {
     186        digit = value % radix;
     187        value = value / radix;
     188        if (digit < 10) {
     189            *--pos = '0' + digit;
     190        } else {
     191            *--pos = 'a' + digit - 10;
     192        } /* if */
     193    } while (value != 0L);
     194
     195    memcpy(str, pos, &buffer[64] - pos + 1);
     196    return str;
     197}
     198
     199
     200/*********************************************************************
     201 *      _i64toa   (NTDLL.@)
     202 *
     203 * Converts a large integer to a string.
     204 *
     205 * Assigns a '\0' terminated string to str and returns str. If radix
     206 * is 10 and value is negative, the value is converted with sign.
     207 * Does not check if radix is in the range of 2 to 36 (as native DLL).
     208 * For str == NULL just crashes (as native DLL).
     209 *
     210 * Difference:
     211 * - The native DLL converts negative values (for base 10) wrong:
     212 *                     -1 is converted to -18446744073709551615
     213 *                     -2 is converted to -18446744073709551614
     214 *   -9223372036854775807 is converted to  -9223372036854775809
     215 *   -9223372036854775808 is converted to  -9223372036854775808
     216 *   The native msvcrt _i64toa function and our ntdll function do
     217 *   not have this bug.
     218 */
     219char * __cdecl _i64toa( LONGLONG value, char *str, int radix )
     220{
     221    ULONGLONG val;
     222    int negative;
     223    char buffer[65];
     224    char *pos;
     225    int digit;
     226
     227    if (value < 0 && radix == 10) {
     228        negative = 1;
     229        val = -value;
     230    } else {
     231        negative = 0;
     232        val = value;
     233    } /* if */
     234
     235    pos = &buffer[64];
     236    *pos = '\0';
     237
     238    do {
     239        digit = val % radix;
     240        val = val / radix;
     241        if (digit < 10) {
     242            *--pos = '0' + digit;
     243        } else {
     244            *--pos = 'a' + digit - 10;
     245        } /* if */
     246    } while (val != 0L);
     247
     248    if (negative) {
     249        *--pos = '-';
     250    } /* if */
     251
     252    memcpy(str, pos, &buffer[64] - pos + 1);
     253    return str;
     254}
     255
     256
     257/*********************************************************************
     258 *      _atoi64   (NTDLL.@)
     259 *
     260 * Converts a string to a large integer.
     261 *
     262 * On success it returns the integer value otherwise it returns 0.
     263 * Accepts: {whitespace} [+|-] {digits}
     264 * No check of overflow: Just assigns lower 64 bits (as native DLL).
     265 * Does not check for str != NULL (as native DLL).
     266 */
     267LONGLONG __cdecl _atoi64( char *str )
     268{
     269    ULONGLONG RunningTotal = 0;
     270    char bMinus = 0;
     271
     272    while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
     273        str++;
     274    } /* while */
     275
     276    if (*str == '+') {
     277        str++;
     278    } else if (*str == '-') {
     279        bMinus = 1;
     280        str++;
     281    } /* if */
     282
     283    while (*str >= '0' && *str <= '9') {
     284        RunningTotal = RunningTotal * 10 + *str - '0';
     285        str++;
     286    } /* while */
     287
     288    return bMinus ? -RunningTotal : RunningTotal;
    125289}
    126290
Note: See TracChangeset for help on using the changeset viewer.