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

📄 fiolib.c

📁 the vxworks system kernel souce packeg.there may be something you need .
💻 C
📖 第 1 页 / 共 5 页
字号:
    return (original_maxbytes);    }/********************************************************************************* fioRdString - read a string from a file** This routine puts a line of input into <string>.  The specified input* file descriptor is read until <maxbytes>, an EOF, an EOS, or a newline* character is reached.  A newline character or EOF is replaced with EOS,* unless <maxbytes> characters have been read.** RETURNS:* The length of the string read, including the terminating EOS;* or EOF if a read error occurred or end-of-file occurred without* reading any other character.*/int fioRdString    (    int fd,             /* fd of device to read */    FAST char string[], /* buffer to receive input */    int maxbytes        /* max no. of chars to read */    )    {    char c;    FAST int nchars = 0;    FAST int i = 0;    /* read characters until     *    1) specified line limit is reached,     *    2) end-of-file is reached,     *    3) EOS character is read,     *    4) newline character is read,     * or 5) read error occurs.     */    while (i < maxbytes)	{	nchars = read (fd, &c, 1);	if (nchars == ERROR)			/* if can't read file */	    break;	/* check for newline terminator */	if ((nchars != 1) || (c == '\n') || (c == EOS))	    {	    string [i++] = EOS;	    break;	    }	string [i++] = c;	}    if (nchars == ERROR  || ((nchars == 0) && (i == 1)))	i = EOF;    return (i);    }/********************************************************************************* sscanf - read and convert characters from an ASCII string (ANSI)** This routine reads characters from the string <str>, interprets them* according to format specifications in the string <fmt>, which specifies* the admissible input sequences and how they are to be converted for* assignment, using subsequent arguments as pointers to the objects to* receive the converted input.** If there are insufficient arguments for the format, the behavior is* undefined.  If the format is exhausted while arguments remain, the excess* arguments are evaluated but are otherwise ignored.** The format is a multibyte character sequence, beginning and ending in* its initial shift state.  The format is composed of zero or more directives:* one or more white-space characters; an ordinary multibyte character (neither* `%' nor a white-space character); or a conversion specification.  Each* conversion specification is introduced by the `%' character.  After the `%',* the following appear in sequence:** .iP "" 4* An optional assignment-suppressing character `*'.* .iP* An optional non-zero decimal integer that specifies the maximum field * width.* .iP* An optional `h', `l' (ell) or `ll' (ell-ell) indicating the size of the * receiving object.  The conversion specifiers `d', `i', and `n' should * be preceded by `h' if the corresponding argument is a pointer to `short * int' rather than a pointer to `int', or by `l' if it is a pointer to * `long int', or by `ll' if it is a pointer to `long long int'.  Similarly, * the conversion specifiers `o', `u', and `x' shall be preceded by `h' if * the corresponding argument is a pointer to `unsigned short int' rather * than a pointer to `unsigned int', or by `l' if it is a pointer to * `unsigned long int', or by `ll' if it is a pointer to `unsigned long * long int'.  Finally, the conversion specifiers `e', `f', and `g' shall * be preceded by `l' if the corresponding argument is a pointer to * `double' rather than a pointer to `float'.  If a `h', `l' or `ll' * appears with any other conversion specifier, the behavior is undefined.* .iP* \&WARNING: ANSI C also specifies an optional `L' in some of the same* contexts as `l' above, corresponding to a `long double *' argument.* However, the current release of the VxWorks libraries does not support * `long double' data; using the optional `L' gives unpredictable results.* .iP* A character that specifies the type of conversion to be applied.  The* valid conversion specifiers are described below.* .LP** The sscanf() routine executes each directive of the format in turn.  If a * directive fails, as detailed below, sscanf() returns.  Failures* are described as input failures (due to the unavailability of input* characters), or matching failures (due to inappropriate input).* * A directive composed of white-space character(s) is executed by reading* input up to the first non-white-space character (which remains unread),* or until no more characters can be read.** A directive that is an ordinary multibyte character is executed by reading* the next characters of the stream.  If one of the characters differs from* one comprising the directive, the directive fails, and the differing and* subsequent characters remain unread.** A directive that is a conversion specification defines a set of matching* input sequences, as described below for each specifier.  A conversion* specification is executed in the following steps:** Input white-space characters (as specified by the isspace() function) are * skipped, unless the specification includes a `[', `c', or `n' specifier.** An input item is read from the stream, unless the specification includes* an `n' specifier.  An input item is defined as the longest matching* sequence of input characters, unless that exceeds a specified field width,* in which case it is the initial subsequence of that length in the* sequence.  The first character, if any, after the input item remains* unread.  If the length of the input item is zero, the execution of the* directive fails:  this condition is a matching failure, unless an error* prevented input from the stream, in which case it is an input failure.** Except in the case of a `%' specifier, the input item is converted to a* type appropriate to the conversion specifier.  If the input item is not a* matching sequence, the execution of the directive fails:  this condition* is a matching failure.  Unless assignment suppression was indicated by a* `*', the result of the conversion is placed in the object pointed to by* the first argument following the <fmt> argument that has not already* received a conversion result.  If this object does not have an appropriate* type, or if the result of the conversion cannot be represented in the* space provided, the behavior is undefined.** The following conversion specifiers are valid:** .iP `d'* Matches an optionally signed decimal integer whose format is* the same as expected for the subject sequence of the strtol()* function with the value 10 for the <base> argument.  The * corresponding argument should be a pointer to `int'.* .iP `i'* Matches an optionally signed integer, whose format is the* same as expected for the subject sequence of the strtol()* function with the value 0 for the <base> argument.  The * corresponding argument should be a pointer to `int'.* .iP `o'* Matches an optionally signed octal integer, whose format is the* same as expected for the subject sequence of the strtoul()* function with the value 8 for the <base> argument.  The* corresponding argument should be a pointer to `unsigned int'.* .iP `u'* Matches an optionally signed decimal integer, whose format is * the same as expected for the subject sequence of the strtoul()* function with the value 10 for the <base> argument.  The* corresponding argument should be a pointer to `unsigned int'.* .iP `x'* Matches an optionally signed hexadecimal integer, whose format is* the same as expected for the subject sequence of the strtoul()* function with the value 16 for the <base> argument.  The* corresponding argument should be a pointer to `unsigned int'.* .iP "`e', `f', `g'"* Match an optionally signed floating-point number, whose format* is the same as expected for the subject string of the strtod()* function.  The corresponding argument should be a pointer to `float'.* .iP `s'* Matches a sequence of non-white-space characters.  The * corresponding argument should be a pointer to the initial* character of an array large enough to accept the sequence* and a terminating null character, which will be added * automatically.* .iP `['* Matches a non-empty sequence of characters from a set of * expected characters (the `scanset').  The corresponding argument* should be a pointer to the initial character of an array large* enough to accept the sequence and a terminating null character,* which is added automatically.  The conversion specifier* includes all subsequent character in the format string, up to* and including the matching right bracket (`]').  The characters* between the brackets (the `scanlist') comprise the scanset,* unless the character after the left bracket is a circumflex (`^')* in which case the scanset contains all characters that do not* appear in the scanlist between the circumflex and the right* bracket.  If the conversion specifier begins with "[]" or "[^]", the* right bracket character is in the scanlist and the next * right bracket character is the matching right bracket that ends* the specification; otherwise the first right bracket character* is the one that ends the specification.* .iP `c'* Matches a sequence of characters of the number specified by the* field width (1 if no field width is present in the directive).* The corresponding argument should be a pointer to the initial * character of an array large enough to accept the sequence.* No null character is added.* .iP `p'* Matches an implementation-defined set of sequences, which should be* the same as the set of sequences that may be produced by the %p* conversion of the fprintf() function.  The corresponding argument* should be a pointer to a pointer to `void'.  VxWorks defines its* pointer input field to be consistent with pointers written by the* fprintf() function ("0x" hexadecimal notation).  If the input item is* a value converted earlier during the same program execution, the* pointer that results should compare equal to that value; otherwise* the behavior of the %p conversion is undefined.* .iP `n'* No input is consumed.  The corresponding argument should be a pointer to* `int' into which the number of characters read from the input stream so* far by this call to sscanf() is written.  Execution of a %n directive does* not increment the assignment count returned when sscanf() completes* execution.* .iP `%'* Matches a single `%'; no conversion or assignment occurs.  The* complete conversion specification is %%.* .LP** If a conversion specification is invalid, the behavior is undefined.** The conversion specifiers `E', `G', and `X' are also valid and behave the* same as `e', `g', and `x', respectively.** If end-of-file is encountered during input, conversion is terminated.  If * end-of-file occurs before any characters matching the current directive* have been read (other than leading white space, where permitted), execution* of the current directive terminates with an input failure; otherwise, unless* execution of the current directive is terminated with a matching failure,* execution of the following directive (if any) is terminated with an input* failure.** If conversion terminates on a conflicting input character, the offending* input character is left unread in the input stream.  Trailing white space* (including new-line characters) is left unread unless matched by a* directive.  The success of literal matches and suppressed assignments is* not directly determinable other than via the %n directive.** INCLUDE FILES: fioLib.h ** RETURNS:* The number of input items assigned, which can be fewer than provided for,* or even zero, in the event of an early matching failure; or EOF if an* input failure occurs before any conversion.** SEE ALSO: fscanf(), scanf(),* .I "American National Standard for Information Systems -"* .I "Programming Language - C, ANSI X3.159-1989: Input/Output (stdio.h)"** VARARGS2*/int sscanf    (    const char *  str,	/* string to scan */    const char *  fmt,	/* format string */    ...      		/* optional arguments to format string */    )    {    int		nArgs;    int		unget;    va_list	vaList;			/* vararg list */    va_start (vaList, fmt);    nArgs = fioScanV (fmt, getbuf, (int) &str, &unget, vaList);    va_end (vaList);    return (nArgs);    }/********************************************************************************* getbuf - sscanf() support routine: get next character in string** RETURNS: Next character or EOF if empty.*/LOCAL int getbuf    (    char **str    )    {    int c = (int)(**str);    if (c == EOS)        return (EOF);    ++*str;    return (c);    }/******************************************************************************** fioScanV - scan processor** NOMANUAL*/int fioScanV    (    const char *fmt,            /* the format string */    FUNCPTR     getRtn,         /* routine to get next character */    int         getArg,         /* argument to be passed to get */    int *       pUnget,         /* where to return unget char (-1 = no unget) */    va_list     vaList          /* vararg list */    )    {    BOOL        suppress;                       /* assignment was suppressed */    void *      pArg;    int         ch;    BOOL        countArg;                       /* FALSE for %n, not counted */    BOOL        quit            = FALSE;    int         argsAssigned    = 0;    int         nchars          = 0;     pArg = va_arg (vaList, void *);     /* get first pointer arg */     ch = (* getRtn) (getArg);           /* get first char */      while (!quit && (*fmt != EOS))        {        countArg = TRUE;                /* default = count arg assignment */         switch (*fmt)            {            case ' ':            case '\n':            case '\t':                  /* skip white space in string */                ++fmt;                while (isspace (ch))                    GET_CHAR (ch, nchars);                break;             case '%':                   /* conversion specification */                ++fmt;                 /* NOTE: if next char is '%' (i.e. "%%") then a normal match                 * of '%' is required: FALL THROUGH to default case                 */                if (*fmt != '%')                    {                    /* Skip white space except for 'c', 'n', '[' specifiers.                     * Suppress including %n fields in returned count.                     */                     switch (*fmt)                        {                        case 'c':                        case '[':                            break;                        case '*':  /* ignore the '*' for purposes of white			            * space removal                        */			    switch(*(fmt+1))			        {				case 'c':				case '[':				    break;                        	default:                            	    while (isspace (ch))                                	GET_CHAR (ch, nchars);				}			    break;								                        case 'n':                            countArg = FALSE;           /* we don't count %n */                            break;                         case 'h':                       /* %hn, %ln, %Ln, %lln */			case 'l':			case 'L':			    if ((*(fmt + 1) == 'n') || 			        ((*fmt == 'l') && (*(fmt + 1) == 'l') && (*(fmt + 2) == 'n')))                                 {			        countArg = FALSE;

⌨️ 快捷键说明

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