]>
git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/fmtcheck.c
2 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * This code was contributed to The NetBSD Foundation by Allen Briggs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 /* $NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp $ */
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD: src/lib/libc/gen/fmtcheck.c,v 1.5 2002/06/27 13:20:54 deischen Exp $");
44 __weak_reference(__fmtcheck
, fmtcheck
);
46 enum __e_fmtcheck_types
{
52 FMTCHECK_SHORTPOINTER
,
64 typedef enum __e_fmtcheck_types EFT
;
66 #define RETURN(pf,f,r) do { \
69 } /*NOTREACHED*/ /*CONSTCOND*/ while (0)
72 get_next_format_from_precision(const char **pf
)
74 int sh
, lg
, quad
, longdouble
;
77 sh
= lg
= quad
= longdouble
= 0;
87 if (!*f
) RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
106 if (!*f
) RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
107 if (strchr("diouxX", *f
)) {
109 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
111 RETURN(pf
,f
,FMTCHECK_LONG
);
113 RETURN(pf
,f
,FMTCHECK_QUAD
);
114 RETURN(pf
,f
,FMTCHECK_INT
);
118 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
120 RETURN(pf
,f
,FMTCHECK_SHORTPOINTER
);
122 RETURN(pf
,f
,FMTCHECK_LONGPOINTER
);
124 RETURN(pf
,f
,FMTCHECK_QUADPOINTER
);
125 RETURN(pf
,f
,FMTCHECK_INTPOINTER
);
127 if (strchr("DOU", *f
)) {
128 if (sh
+ lg
+ quad
+ longdouble
)
129 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
130 RETURN(pf
,f
,FMTCHECK_LONG
);
132 if (strchr("eEfg", *f
)) {
134 RETURN(pf
,f
,FMTCHECK_LONGDOUBLE
);
136 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
137 RETURN(pf
,f
,FMTCHECK_DOUBLE
);
140 if (sh
+ lg
+ quad
+ longdouble
)
141 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
142 RETURN(pf
,f
,FMTCHECK_INT
);
145 if (sh
+ lg
+ quad
+ longdouble
)
146 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
147 RETURN(pf
,f
,FMTCHECK_STRING
);
150 if (sh
+ lg
+ quad
+ longdouble
)
151 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
152 RETURN(pf
,f
,FMTCHECK_LONG
);
154 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
159 get_next_format_from_width(const char **pf
)
167 RETURN(pf
,f
,FMTCHECK_PRECISION
);
169 /* eat any precision (empty is allowed) */
170 while (isdigit(*f
)) f
++;
171 if (!*f
) RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
173 RETURN(pf
,f
,get_next_format_from_precision(pf
));
178 get_next_format(const char **pf
, EFT eft
)
183 if (eft
== FMTCHECK_WIDTH
) {
185 return get_next_format_from_width(pf
);
186 } else if (eft
== FMTCHECK_PRECISION
) {
188 return get_next_format_from_precision(pf
);
196 RETURN(pf
,f
,FMTCHECK_DONE
);
199 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
206 /* Eat any of the flags */
207 while (*f
&& (strchr("#0- +", *f
)))
211 RETURN(pf
,f
,FMTCHECK_WIDTH
);
214 while (isdigit(*f
)) f
++;
216 RETURN(pf
,f
,FMTCHECK_UNKNOWN
);
219 RETURN(pf
,f
,get_next_format_from_width(pf
));
224 __fmtcheck(const char *f1
, const char *f2
)
226 const char *f1p
, *f2p
;
232 f1t
= FMTCHECK_START
;
234 f2t
= FMTCHECK_START
;
235 while ((f1t
= get_next_format(&f1p
, f1t
)) != FMTCHECK_DONE
) {
236 if (f1t
== FMTCHECK_UNKNOWN
)
238 f2t
= get_next_format(&f2p
, f2t
);