[444] | 1 | /* |
---|
| 2 | * Copyright (c) 1990 The Regents of the University of California. |
---|
| 3 | * All rights reserved. |
---|
| 4 | * |
---|
| 5 | * Redistribution and use in source and binary forms are permitted |
---|
| 6 | * provided that the above copyright notice and this paragraph are |
---|
| 7 | * duplicated in all such forms and that any documentation, |
---|
| 8 | * advertising materials, and other materials related to such |
---|
| 9 | * distribution and use acknowledge that the software was developed |
---|
| 10 | * by the University of California, Berkeley. The name of the |
---|
| 11 | * University may not be used to endorse or promote products derived |
---|
| 12 | * from this software without specific prior written permission. |
---|
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
| 14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | FUNCTION |
---|
| 20 | <<siscanf>>, <<fiscanf>>, <<iscanf>>---scan and format non-floating input |
---|
| 21 | |
---|
| 22 | INDEX |
---|
| 23 | iscanf |
---|
| 24 | INDEX |
---|
| 25 | _iscanf_r |
---|
| 26 | INDEX |
---|
| 27 | fiscanf |
---|
| 28 | INDEX |
---|
| 29 | _fiscanf_r |
---|
| 30 | INDEX |
---|
| 31 | siscanf |
---|
| 32 | INDEX |
---|
| 33 | _siscanf_r |
---|
| 34 | |
---|
| 35 | SYNOPSIS |
---|
| 36 | #include <stdio.h> |
---|
| 37 | |
---|
| 38 | int iscanf(const char *<[format]>, ...); |
---|
| 39 | int fiscanf(FILE *<[fd]>, const char *<[format]>, ...); |
---|
| 40 | int siscanf(const char *<[str]>, const char *<[format]>, ...); |
---|
| 41 | |
---|
| 42 | int _iscanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); |
---|
| 43 | int _fiscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, |
---|
| 44 | const char *<[format]>, ...); |
---|
| 45 | int _siscanf_r(struct _reent *<[ptr]>, const char *<[str]>, |
---|
| 46 | const char *<[format]>, ...); |
---|
| 47 | |
---|
| 48 | DESCRIPTION |
---|
| 49 | <<iscanf>>, <<fiscanf>>, and <<siscanf>> are the same as |
---|
| 50 | <<scanf>>, <<fscanf>>, and <<sscanf>> respectively, only that |
---|
| 51 | they restrict the available formats to non-floating-point |
---|
| 52 | format specifiers. |
---|
| 53 | |
---|
| 54 | The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant |
---|
| 55 | versions of <<iscanf>>, <<fiscanf>>, and <<siscanf>> that take an additional |
---|
| 56 | first argument pointing to a reentrancy structure. |
---|
| 57 | |
---|
| 58 | RETURNS |
---|
| 59 | <<iscanf>> returns the number of input fields successfully |
---|
| 60 | scanned, converted and stored; the return value does |
---|
| 61 | not include scanned fields which were not stored. |
---|
| 62 | |
---|
| 63 | If <<iscanf>> attempts to read at end-of-file, the return |
---|
| 64 | value is <<EOF>>. |
---|
| 65 | |
---|
| 66 | If no fields were stored, the return value is <<0>>. |
---|
| 67 | |
---|
| 68 | PORTABILITY |
---|
| 69 | <<iscanf>>, <<fiscanf>>, and <<siscanf>> are newlib extensions. |
---|
| 70 | |
---|
| 71 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
---|
| 72 | <<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
---|
| 73 | */ |
---|
| 74 | |
---|
| 75 | #include <_ansi.h> |
---|
| 76 | #include <reent.h> |
---|
| 77 | #include <stdio.h> |
---|
| 78 | #include <string.h> |
---|
| 79 | #include <stdarg.h> |
---|
| 80 | #include "local.h" |
---|
| 81 | |
---|
| 82 | #ifndef _REENT_ONLY |
---|
| 83 | |
---|
| 84 | int |
---|
| 85 | siscanf (const char *str, |
---|
| 86 | const char *fmt, ...) |
---|
| 87 | { |
---|
| 88 | int ret; |
---|
| 89 | va_list ap; |
---|
| 90 | FILE f; |
---|
| 91 | |
---|
| 92 | f._flags = __SRD | __SSTR; |
---|
| 93 | f._bf._base = f._p = (unsigned char *) str; |
---|
| 94 | f._bf._size = f._r = strlen (str); |
---|
| 95 | f._read = __seofread; |
---|
| 96 | f._ub._base = NULL; |
---|
| 97 | f._lb._base = NULL; |
---|
| 98 | f._file = -1; /* No file. */ |
---|
| 99 | va_start (ap, fmt); |
---|
| 100 | ret = __ssvfiscanf_r (_REENT, &f, fmt, ap); |
---|
| 101 | va_end (ap); |
---|
| 102 | return ret; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | #endif /* !_REENT_ONLY */ |
---|
| 106 | |
---|
| 107 | int |
---|
| 108 | _siscanf_r (struct _reent *ptr, |
---|
| 109 | const char *str, |
---|
| 110 | const char *fmt, ...) |
---|
| 111 | { |
---|
| 112 | int ret; |
---|
| 113 | va_list ap; |
---|
| 114 | FILE f; |
---|
| 115 | |
---|
| 116 | f._flags = __SRD | __SSTR; |
---|
| 117 | f._bf._base = f._p = (unsigned char *) str; |
---|
| 118 | f._bf._size = f._r = strlen (str); |
---|
| 119 | f._read = __seofread; |
---|
| 120 | f._ub._base = NULL; |
---|
| 121 | f._lb._base = NULL; |
---|
| 122 | f._file = -1; /* No file. */ |
---|
| 123 | va_start (ap, fmt); |
---|
| 124 | ret = __ssvfiscanf_r (ptr, &f, fmt, ap); |
---|
| 125 | va_end (ap); |
---|
| 126 | return ret; |
---|
| 127 | } |
---|