Define __have_atfcts global in stub openat implementation.
[glibc.git] / stdio-common / printf-parse.h
blob3aa0274249ba0440a8ae10df0cfb63025b56906b
1 /* Internal header for parsing printf format strings.
2 Copyright (C) 1995-1999, 2000, 2002, 2003, 2007, 2009
3 Free Software Foundation, Inc.
4 This file is part of th GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <printf.h>
21 #include <stdint.h>
22 #include <stddef.h>
23 #include <string.h>
24 #include <wchar.h>
27 struct printf_spec
29 /* Information parsed from the format spec. */
30 struct printf_info info;
32 /* Pointers into the format string for the end of this format
33 spec and the next (or to the end of the string if no more). */
34 const UCHAR_T *end_of_fmt, *next_fmt;
36 /* Position of arguments for precision and width, or -1 if `info' has
37 the constant value. */
38 int prec_arg, width_arg;
40 int data_arg; /* Position of data argument. */
41 int data_arg_type; /* Type of first argument. */
42 /* Number of arguments consumed by this format specifier. */
43 size_t ndata_args;
44 /* Size of the parameter for PA_USER type. */
45 int size;
49 /* The various kinds off arguments that can be passed to printf. */
50 union printf_arg
52 wchar_t pa_wchar;
53 int pa_int;
54 long int pa_long_int;
55 long long int pa_long_long_int;
56 unsigned int pa_u_int;
57 unsigned long int pa_u_long_int;
58 unsigned long long int pa_u_long_long_int;
59 double pa_double;
60 long double pa_long_double;
61 const char *pa_string;
62 const wchar_t *pa_wstring;
63 void *pa_pointer;
64 void *pa_user;
68 #ifndef DONT_NEED_READ_INT
69 /* Read a simple integer from a string and update the string pointer.
70 It is assumed that the first character is a digit. */
71 static int
72 read_int (const UCHAR_T * *pstr)
74 int retval = **pstr - L_('0');
76 while (ISDIGIT (*++(*pstr)))
77 if (retval >= 0)
79 if (INT_MAX / 10 < retval)
80 retval = -1;
81 else
83 int digit = **pstr - L_('0');
85 retval *= 10;
86 if (INT_MAX - digit < retval)
87 retval = -1;
88 else
89 retval += digit;
93 return retval;
95 #endif
98 /* These are defined in reg-printf.c. */
99 extern printf_arginfo_size_function **__printf_arginfo_table attribute_hidden;
100 extern printf_function **__printf_function_table attribute_hidden;
101 extern printf_va_arg_function **__printf_va_arg_table attribute_hidden;
104 /* Find the next spec in FORMAT, or the end of the string. Returns
105 a pointer into FORMAT, to a '%' or a '\0'. */
106 __extern_always_inline const unsigned char *
107 __find_specmb (const unsigned char *format)
109 return (const unsigned char *) __strchrnul ((const char *) format, '%');
112 __extern_always_inline const unsigned int *
113 __find_specwc (const unsigned int *format)
115 return (const unsigned int *) __wcschrnul ((const wchar_t *) format, L'%');
119 /* FORMAT must point to a '%' at the beginning of a spec. Fills in *SPEC
120 with the parsed details. POSN is the number of arguments already
121 consumed. At most MAXTYPES - POSN types are filled in TYPES. Return
122 the number of args consumed by this spec; *MAX_REF_ARG is updated so it
123 remains the highest argument index used. */
124 extern size_t __parse_one_specmb (const unsigned char *format, size_t posn,
125 struct printf_spec *spec,
126 size_t *max_ref_arg) attribute_hidden;
128 extern size_t __parse_one_specwc (const unsigned int *format, size_t posn,
129 struct printf_spec *spec,
130 size_t *max_ref_arg) attribute_hidden;
134 /* This variable is defined in reg-modifier.c. */
135 struct printf_modifier_record;
136 extern struct printf_modifier_record **__printf_modifier_table
137 attribute_hidden;
139 /* Handle registered modifiers. */
140 extern int __handle_registered_modifier_mb (const unsigned char **format,
141 struct printf_info *info)
142 attribute_hidden;
143 extern int __handle_registered_modifier_wc (const unsigned int **format,
144 struct printf_info *info)
145 attribute_hidden;