2.9
[glibc/nacl-glibc.git] / stdio-common / printf.h
blob360cdcce1d21fa903b9579e91fff0e4529716ca1
1 /* Copyright (C) 1991-1993,1995-1999,2000,2001,2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _PRINTF_H
22 #define _PRINTF_H 1
23 #include <features.h>
25 __BEGIN_DECLS
27 #define __need_FILE
28 #include <stdio.h>
29 #define __need_size_t
30 #define __need_wchar_t
31 #include <stddef.h>
34 struct printf_info
36 int prec; /* Precision. */
37 int width; /* Width. */
38 wchar_t spec; /* Format letter. */
39 unsigned int is_long_double:1;/* L flag. */
40 unsigned int is_short:1; /* h flag. */
41 unsigned int is_long:1; /* l flag. */
42 unsigned int alt:1; /* # flag. */
43 unsigned int space:1; /* Space flag. */
44 unsigned int left:1; /* - flag. */
45 unsigned int showsign:1; /* + flag. */
46 unsigned int group:1; /* ' flag. */
47 unsigned int extra:1; /* For special use. */
48 unsigned int is_char:1; /* hh flag. */
49 unsigned int wide:1; /* Nonzero for wide character streams. */
50 unsigned int i18n:1; /* I flag. */
51 wchar_t pad; /* Padding character. */
55 /* Type of a printf specifier-handler function.
56 STREAM is the FILE on which to write output.
57 INFO gives information about the format specification.
58 ARGS is a vector of pointers to the argument data;
59 the number of pointers will be the number returned
60 by the associated arginfo function for the same INFO.
62 The function should return the number of characters written,
63 or -1 for errors. */
65 typedef int printf_function (FILE *__stream,
66 __const struct printf_info *__info,
67 __const void *__const *__args);
69 /* Type of a printf specifier-arginfo function.
70 INFO gives information about the format specification.
71 N, ARGTYPES, and return value are as for parse_printf_format. */
73 typedef int printf_arginfo_function (__const struct printf_info *__info,
74 size_t __n, int *__argtypes);
77 /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
78 specified to determine how many arguments a SPEC conversion requires and
79 what their types are. */
81 extern int register_printf_function (int __spec, printf_function __func,
82 printf_arginfo_function __arginfo);
85 /* Parse FMT, and fill in N elements of ARGTYPES with the
86 types needed for the conversions FMT specifies. Returns
87 the number of arguments required by FMT.
89 The ARGINFO function registered with a user-defined format is passed a
90 `struct printf_info' describing the format spec being parsed. A width
91 or precision of INT_MIN means a `*' was used to indicate that the
92 width/precision will come from an arg. The function should fill in the
93 array it is passed with the types of the arguments it wants, and return
94 the number of arguments it wants. */
96 extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n,
97 int *__restrict __argtypes) __THROW;
100 /* Codes returned by `parse_printf_format' for basic types.
102 These values cover all the standard format specifications.
103 Users can add new values after PA_LAST for their own types. */
105 enum
106 { /* C type: */
107 PA_INT, /* int */
108 PA_CHAR, /* int, cast to char */
109 PA_WCHAR, /* wide char */
110 PA_STRING, /* const char *, a '\0'-terminated string */
111 PA_WSTRING, /* const wchar_t *, wide character string */
112 PA_POINTER, /* void * */
113 PA_FLOAT, /* float */
114 PA_DOUBLE, /* double */
115 PA_LAST
118 /* Flag bits that can be set in a type returned by `parse_printf_format'. */
119 #define PA_FLAG_MASK 0xff00
120 #define PA_FLAG_LONG_LONG (1 << 8)
121 #define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG
122 #define PA_FLAG_LONG (1 << 9)
123 #define PA_FLAG_SHORT (1 << 10)
124 #define PA_FLAG_PTR (1 << 11)
128 /* Function which can be registered as `printf'-handlers. */
130 /* Print floating point value using using abbreviations for the orders
131 of magnitude used for numbers ('k' for kilo, 'm' for mega etc). If
132 the format specifier is a uppercase character powers of 1000 are
133 used. Otherwise powers of 1024. */
134 extern int printf_size (FILE *__restrict __fp,
135 __const struct printf_info *__info,
136 __const void *__const *__restrict __args) __THROW;
138 /* This is the appropriate argument information function for `printf_size'. */
139 extern int printf_size_info (__const struct printf_info *__restrict
140 __info, size_t __n, int *__restrict __argtypes)
141 __THROW;
143 #ifdef __LDBL_COMPAT
144 # include <bits/printf-ldbl.h>
145 #endif
147 __END_DECLS
149 #endif /* printf.h */