⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _strtol.c

📁 test file nucleus source
💻 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**       _strtol.c                               Nucleus Common Library 1.1** DESCRIPTION**       This file contains the implementation of NCL_strtol.** DATA STRUCTURES**       None.** FUNCTIONS**       NCL_strtol** 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__strtol**   DESCRIPTION**       This routine is used to scan a single long integer from at most*       'width' characters in a string.  If 'width' is negative, the*       number of characters scanned is unlimited.  The integer may be*       preceeded by an optional sign character, but whitespace*       characters are invalid.  In other respects, it acts like "strtol".**   INPUTS**       nptr                Null-terminated string to convert*       base                Number system (binary, hex, octal, etc...)*       width               The most chars in the string this function*                             will operate upon.  If negative, there is*                             no limit for this function.*       max                 Largest value that will not cause an overflow**   OUTPUTS**       long                Value the string represents**************************************************************************/long NCL__strtol (const char *nptr, char **endptr, int base, int width){    rcchar *ptr = nptr;    ulong  uvalue;    long   svalue;    int    neg = 0;    char   *eptr;    NU_SUPERV_USER_VARIABLES    if (*ptr == '-')    {        neg = 1;        goto do_sign;    }    /* get optional sign */    if (*ptr == '+')    {        do_sign:        if (width == 0)        {            eptr = (char *)nptr;            svalue = 0L;            goto exit;        }        if (width > 0)            --width;        ++ptr;    }    switch (NCL__str2ul (&uvalue, ptr, &eptr, width, base))    {        case S2L_ERROR:            svalue = 0L;            eptr = (char *)nptr;            if (width && *ptr == '0') /* "0x?" is valid */            eptr = (char *)(ptr + 1);            break;        case S2L_VALID:            if (neg)            {                if (uvalue > - (unsigned long) LONG_MIN)                    goto overflow;                svalue = SNEGATE(uvalue);            }            else  /* positive */            {                if (uvalue >   (unsigned long) LONG_MAX)                    goto overflow;                svalue = (long) uvalue;            }            break;        case S2L_OVFLW:overflow:            svalue = ((neg) ? LONG_MIN : LONG_MAX);            NU_SUPERVISOR_MODE();            errno = ERANGE;            NU_USER_MODE();            break;    }exit:    if (endptr != (char**)0)        *endptr = eptr;    return (svalue);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -