📄 _strtoul.c
字号:
/*************************************************************************
*
* Copyright Mentor Graphics Corporation 2002
* All Rights Reserved.
*
* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS
* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS
* SUBJECT TO LICENSE TERMS.
*
*************************************************************************/
/*************************************************************************
* FILE NAME VERSION
*
* _strtoul.c Nucleus Common Library 1.1
*
* DESCRIPTION
*
* This file contains the implementation of NCL__strtoul.
*
* DATA STRUCTURES
*
* None.
*
* FUNCTIONS
*
* NCL__strtoul
*
* DEPENDENCIES
*
* ncl.h
* abbr.h
* errno.h
* convert.h
* nucleus.h
*
************************************************************************/
#define NU_NCL_SOURCE_FILE
#include "ncl\inc\ncl.h"
#include "ncl\inc\abbr.h" /* rcchar */
#include "ncl\inc\errno.h"
#include "ncl\inc\convert.h"
#include "plus\nucleus.h" /* MMU Support */
/*************************************************************************
*
* FUNCTION
*
* NCL__strtoul
*
* DESCRIPTION
*
* The routine is used to scan a single unsigned long integer from
* at most 'width' characters in a string. If 'width' is negative,
* there is no limit to the number of characters scanned. The
* integer may be preceeded by an optional sign character, but
* whitespace characters are invalid. The 'max' value determines
* the largest value which will not cause overflow. If the converted
* value exceeds 'max', errno will be set to ERANGE and 'max' will be
* returned. In other respects, it acts like "strtoul".
*
* INPUTS
*
* nptr Null-terminated string to converts
* base Number system (binary, hex, octal, etc...)
* width Maximum # of chars to scan (-1 = unlimited)
* max Largest value that will not cause an overflow
*
* OUTPUTS
*
* ulong Value the string represents
*
*************************************************************************/
ulong NCL__strtoul(const char *nptr, char **endptr, int base, int width,
ulong max)
{
rcchar *ptr = nptr;
ulong uvalue;
int neg = 0;
char *eptr;
NU_SUPERV_USER_VARIABLES
if (*ptr == '-') /* get optional sign */
{
neg = 1;
goto do_sign;
}
if (*ptr == '+')
{
do_sign:
if (width == 0)
{
eptr = (char *)nptr;
uvalue = 0L;
goto exit;
}
if (width > 0)
--width;
++ptr;
}
switch (NCL__str2ul (&uvalue, ptr, &eptr, width, base))
{
case S2L_ERROR:
uvalue = 0L;
eptr = (char *)nptr;
if (width && *ptr == '0') /* "0x?" is valid */
eptr = (char *)(ptr + 1);
break;
case S2L_VALID:
if (uvalue > max)
goto overflow; /* check for overflow */
if (neg)
uvalue = -uvalue;
break;
case S2L_OVFLW:
overflow:
uvalue = max;
NU_SUPERVISOR_MODE();
errno = ERANGE;
NU_USER_MODE();
break;
}
exit:
if (endptr)
*endptr = eptr;
return (uvalue);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -