Bring in an errno.9 manual page (based on NetBSD's).
[dragonfly.git] / contrib / gmp / scanf / sscanffuns.c
blob008bad7014590b070ca508cb41bdba847b53875b
1 /* __gmp_sscanf_funs -- support for formatted input from a string.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include "gmp.h"
27 #include "gmp-impl.h"
30 #if 0
31 static int
32 scan (const char **sp, const char *fmt, ...)
34 va_list ap;
35 int ret;
37 va_start(ap, fmt);
38 ret = vsscanf(*sp, fmt, ap);
39 va_end(ap);
41 return ret;
43 #else
44 static int
45 scan (const char **sp, const char *fmt, ...)
47 va_list ap;
48 void *p1, *p2;
49 int ret;
51 va_start (ap, fmt);
52 p1 = va_arg (ap, void *);
53 p2 = va_arg (ap, void *);
55 ret = sscanf (*sp, fmt, p1, p2);
57 va_end (ap);
59 return ret;
61 #endif
63 static void
64 step (const char **sp, int n)
66 ASSERT (n >= 0);
68 /* shouldn't push us past the end of the string */
69 #if WANT_ASSERT
71 int i;
72 for (i = 0; i < n; i++)
73 ASSERT ((*sp)[i] != '\0');
75 #endif
77 (*sp) += n;
80 static int
81 get (const char **sp)
83 const char *s;
84 int c;
85 s = *sp;
86 c = (unsigned char) *s++;
87 if (c == '\0')
88 return EOF;
89 *sp = s;
90 return c;
93 static void
94 unget (int c, const char **sp)
96 const char *s;
97 s = *sp;
98 if (c == EOF)
100 ASSERT (*s == '\0');
101 return;
103 s--;
104 ASSERT ((unsigned char) *s == c);
105 *sp = s;
108 const struct gmp_doscan_funs_t __gmp_sscanf_funs = {
109 (gmp_doscan_scan_t) scan,
110 (gmp_doscan_step_t) step,
111 (gmp_doscan_get_t) get,
112 (gmp_doscan_unget_t) unget,