Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdio / siscanf.c
blob4c1363d0a766532028e38d85b36a90bafd092ab5
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
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 * and/or 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.
19 FUNCTION
20 <<siscanf>>, <<fiscanf>>, <<iscanf>>---scan and format non-floating input
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
35 SYNOPSIS
36 #include <stdio.h>
38 int iscanf(const char *<[format]>, ...);
39 int fiscanf(FILE *<[fd]>, const char *<[format]>, ...);
40 int siscanf(const char *<[str]>, const char *<[format]>, ...);
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]>, ...);
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.
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.
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.
63 If <<iscanf>> attempts to read at end-of-file, the return
64 value is <<EOF>>.
66 If no fields were stored, the return value is <<0>>.
68 PORTABILITY
69 <<iscanf>>, <<fiscanf>>, and <<siscanf>> are newlib extensions.
71 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
72 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
75 #include <_ansi.h>
76 #include <reent.h>
77 #include <stdio.h>
78 #include <string.h>
79 #include <stdarg.h>
80 #include "local.h"
82 #ifndef _REENT_ONLY
84 int
85 siscanf (const char *str,
86 const char *fmt, ...)
88 int ret;
89 va_list ap;
90 FILE f;
92 f._flags = __SRD | __SSTR;
93 f._flags2 = 0;
94 f._bf._base = f._p = (unsigned char *) str;
95 f._bf._size = f._r = strlen (str);
96 f._read = __seofread;
97 f._ub._base = NULL;
98 f._lb._base = NULL;
99 f._file = -1; /* No file. */
100 va_start (ap, fmt);
101 ret = __ssvfiscanf_r (_REENT, &f, fmt, ap);
102 va_end (ap);
103 return ret;
106 #endif /* !_REENT_ONLY */
108 int
109 _siscanf_r (struct _reent *ptr,
110 const char *str,
111 const char *fmt, ...)
113 int ret;
114 va_list ap;
115 FILE f;
117 f._flags = __SRD | __SSTR;
118 f._flags2 = 0;
119 f._bf._base = f._p = (unsigned char *) str;
120 f._bf._size = f._r = strlen (str);
121 f._read = __seofread;
122 f._ub._base = NULL;
123 f._lb._base = NULL;
124 f._file = -1; /* No file. */
125 va_start (ap, fmt);
126 ret = __ssvfiscanf_r (ptr, &f, fmt, ap);
127 va_end (ap);
128 return ret;