diff options
author | Ulrich Drepper <drepper@redhat.com> | 2009-04-11 05:34:20 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2009-04-11 05:34:20 +0000 |
commit | 9d26efa90c6dcbcd6b3e586c9927b6058ef4d529 (patch) | |
tree | fc306e24bf4b956abba8782e78d4118639c46361 /stdio-common/printf.h | |
parent | f140a0d53d639c86408ac532091fb4644faa95c0 (diff) | |
download | glibc-9d26efa90c6dcbcd6b3e586c9927b6058ef4d529.tar.gz glibc-9d26efa90c6dcbcd6b3e586c9927b6058ef4d529.tar.xz glibc-9d26efa90c6dcbcd6b3e586c9927b6058ef4d529.zip |
* stdio-common/printf.h (struct printf_info): Add user element.
New types printf_arginfo_size_function, printf_va_arg_function. Declare register_printf_specifier, register_printf_modifier, register_printf_type. * stdio-common/printf-parse.h (struct printf_spec): Add size element. (union printf_arg): Add pa_user element. Adjust __printf_arginfo_table type. Add __printf_va_arg_table, __printf_modifier_table, __handle_registered_modifier_mb, and __handle_registered_modifier_wc declarations. * stdio-common/printf-parsemb.c: Recognize registered modifiers. If registered arginfo call failed try normal specifier. * stdio-common/printf-prs.c: Pass additional parameter to arginfo function. * stdio-common/Makefile (routines): Add reg-modifier and reg-type. * stdio-common/Versions: Export register_printf_modifier, register_printf_type, and register_printf_specifier for GLIBC_2.10. * stdio-common/reg-modifier.c: New file. * stdio-common/reg-type.c: New file. * stdio-common/reg-printf.c (__register_printf_specifier): New function. Mostly the old __register_printf_function function but uses locking and type of third parameter changed. (__register_printf_function): Implement using __register_printf_specifier. * stdio-common/vfprintf.c (vfprintf): Collect argument sizes in calls to arginfo functions. Allocate enough memory for user-defined types. Call new va_arg functions to get user-defined types. Try installed handlers even for existing format specifiers first.
Diffstat (limited to 'stdio-common/printf.h')
-rw-r--r-- | stdio-common/printf.h | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/stdio-common/printf.h b/stdio-common/printf.h index 360cdcce1d..a11af02274 100644 --- a/stdio-common/printf.h +++ b/stdio-common/printf.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1993,1995-1999,2000,2001,2006 +/* Copyright (C) 1991-1993,1995-2001,2006,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -29,6 +29,7 @@ __BEGIN_DECLS #define __need_size_t #define __need_wchar_t #include <stddef.h> +#include <stdarg.h> struct printf_info @@ -48,6 +49,8 @@ struct printf_info unsigned int is_char:1; /* hh flag. */ unsigned int wide:1; /* Nonzero for wide character streams. */ unsigned int i18n:1; /* I flag. */ + unsigned int __pad:4; /* Unused so far. */ + unsigned short int user; /* Bits for user-installed modifiers. */ wchar_t pad; /* Padding character. */ }; @@ -68,18 +71,55 @@ typedef int printf_function (FILE *__stream, /* Type of a printf specifier-arginfo function. INFO gives information about the format specification. - N, ARGTYPES, and return value are as for parse_printf_format. */ + N, ARGTYPES, *SIZE has to contain the size of the parameter for + user-defined types, and return value are as for parse_printf_format + except that -1 should be returned if the handler cannot handle + this case. This allows to partially overwrite the functionality + of existing format specifiers. */ + +typedef int printf_arginfo_size_function (__const struct printf_info *__info, + size_t __n, int *__argtypes, + int *__size); + +/* Old version of 'printf_arginfo_function' without a SIZE parameter. */ typedef int printf_arginfo_function (__const struct printf_info *__info, size_t __n, int *__argtypes); +/* Type of a function to get a value of a user-defined from the + variable argument list. */ +typedef void printf_va_arg_function (void *__mem, va_list *__ap); + /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be specified to determine how many arguments a SPEC conversion requires and what their types are. */ +extern int register_printf_specifier (int __spec, printf_function __func, + printf_arginfo_size_function __arginfo) + __THROW; + + +/* Obsolete interface similar to register_printf_specifier. It can only + handle basic data types because the ARGINFO callback does not return + information on the size of the user-defined type. */ + extern int register_printf_function (int __spec, printf_function __func, - printf_arginfo_function __arginfo); + printf_arginfo_function __arginfo) + __THROW __attribute_deprecated__; + + +/* Register a new modifier character sequence. If the call succeeds + it returns a positive value representing the bit set in the USER + field in 'struct printf_info'. */ + +extern int register_printf_modifier (wchar_t *__str) __wur __THROW; + + +/* Register variable argument handler for user type. The return value + is to be used in ARGINFO functions to signal the use of the + type. */ +extern int register_printf_type (printf_va_arg_function __fct) __wur __THROW; /* Parse FMT, and fill in N elements of ARGTYPES with the @@ -100,7 +140,8 @@ extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n, /* Codes returned by `parse_printf_format' for basic types. These values cover all the standard format specifications. - Users can add new values after PA_LAST for their own types. */ + Users can reserve new values after PA_LAST for their own types + using 'register_printf_type'. */ enum { /* C type: */ |