/***
*long atol(char *nptr) - Convert string to long
*
*Purpose:
* Converts ASCII string pointed to by nptr to binary.
* Overflow is not detected.
*
*Entry:
* nptr = ptr to string to convert
*
*Exit:
* return long int value of the string
*
*Exceptions:
* None - overflow is not detected.
*
*******************************************************************************/
long __cdecl _tstol(
const _TCHAR *nptr
)
{
int c; /* current char */
long total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
#if defined (_MT) && !defined (_UNICODE)
pthreadlocinfo ptloci = _getptd()->ptlocinfo;
if ( ptloci != __ptlocinfo )
ptloci = __updatetlocinfo();
/* skip whitespace */
while ( __isspace_mt(ptloci, (int)(_TUCHAR)*nptr) )
#else /* defined (_MT) && !defined (_UNICODE) */
while ( _istspace((int)(_TUCHAR)*nptr) )
#endif /* defined (_MT) && !defined (_UNICODE) */
++nptr;
c = (int)(_TUCHAR)*nptr++;
sign = c; /* save sign indication */
if (c == _T('-') || c == _T('+'))
c = (int)(_TUCHAR)*nptr++; /* skip sign */
total = 0;
while ( (c = _tchartodigit(c)) != -1 ) {
total = 10 * total + c; /* accumulate digit */
c = (_TUCHAR)*nptr++; /* get next char */
}
if (sign == '-')
return -total;
else
return total; /* return result, negated if necessary */
}
/***
*int atoi(char *nptr) - Convert string to long
*
*Purpose:
* Converts ASCII string pointed to by nptr to binary.
* Overflow is not detected. Because of this, we can just use
* atol().
*
*Entry:
* nptr = ptr to string to convert
*
*Exit:
* return int value of the string
*
*Exceptions:
* None - overflow is not detected.
*
*******************************************************************************/
__int64 __cdecl _tstoi64(
const _TCHAR *nptr
)
{
int c; /* current char */
__int64 total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
#if defined (_MT) && !defined (_UNICODE)
pthreadlocinfo ptloci = _getptd()->ptlocinfo;
if ( ptloci != __ptlocinfo )
ptloci = __updatetlocinfo();
/* skip whitespace */
while ( __isspace_mt(ptloci, (int)(_TUCHAR)*nptr) )
#else /* defined (_MT) && !defined (_UNICODE) */
while ( _istspace((int)(_TUCHAR)*nptr) )
#endif /* defined (_MT) && !defined (_UNICODE) */
++nptr;
c = (int)(_TUCHAR)*nptr++;
sign = c; /* save sign indication */
if (c == _T('-') || c == _T('+'))
c = (int)(_TUCHAR)*nptr++; /* skip sign */
total = 0;
while ( (c = _tchartodigit(c)) != -1 ) {
total = 10 * total + c; /* accumulate digit */
c = (_TUCHAR)*nptr++; /* get next char */
}
if (sign == _T('-'))
return -total;
else
return total; /* return result, negated if necessary */
}
/*---------------------------------------------------------------------------
* filename - atol.c
*
* function(s)
* atol - converts a string to a long
* atoi - converts a string to an int
* _wtol - converts a wide-character string to a long
* _wtoi - converts a wide-character string to an int
*--------------------------------------------------------------------------*/
/*
* C/C++ Run Time Library - Version 11.0
*
* Copyright (c) 1987, 2002 by Borland Software Corporation
* All Rights Reserved.
*
*/
Name atol, _wtol - converts a string to an integer
Usage long atol(const char *nptr);
long _wtol(const wchar_t *nptr);
Prototype in stdlib.h
Description Convert a string to a long integer. The syntax of
the string must be:
long ::= [isspace]* [sign] digit [digit]*
Only decimal integers are acceptable.
Error handling is poor. The function will protect
itself (crash-proof) but there is no defined method
to return an error indication to the caller. The
result is undefined if the input string is invalid.
Return value converted long value of the input string. If the string
cannot be converted to a long, the return value is 0.
long _RTLENTRY _EXPFUNC _ttol(const _TCHAR *strP)
{
_TCHAR c;
int is_neg;
long result;
result = 0; /* default result is 0 */
while (_istspace((c = *strP++))) /* skip any whitespace characters */
;
if (c == _TEXT('+') || c == _TEXT('-')) /* remember if negative sign seen */
{
is_neg = c == _TEXT('-');
c = *strP++; /* skip sign, get next char */
}
else
is_neg = 0;
while (c >= _TEXT('0') && c <= _TEXT('9')) /* accumulate digits, ignore overflow */
{
result = result * 10 + c - _TEXT('0');
c = *strP++;
}
return (is_neg ? -result : result); /* negate result if '-' seen */
}