1*5af32e75SAxel Dörfler /* Copyright (C) 1991, 1996, 1997, 2002 Free Software Foundation, Inc.
2*5af32e75SAxel Dörfler This file is part of the GNU C Library.
3*5af32e75SAxel Dörfler
4*5af32e75SAxel Dörfler The GNU C Library is free software; you can redistribute it and/or
5*5af32e75SAxel Dörfler modify it under the terms of the GNU Lesser General Public
6*5af32e75SAxel Dörfler License as published by the Free Software Foundation; either
7*5af32e75SAxel Dörfler version 2.1 of the License, or (at your option) any later version.
8*5af32e75SAxel Dörfler
9*5af32e75SAxel Dörfler The GNU C Library is distributed in the hope that it will be useful,
10*5af32e75SAxel Dörfler but WITHOUT ANY WARRANTY; without even the implied warranty of
11*5af32e75SAxel Dörfler MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12*5af32e75SAxel Dörfler Lesser General Public License for more details.
13*5af32e75SAxel Dörfler
14*5af32e75SAxel Dörfler You should have received a copy of the GNU Lesser General Public
15*5af32e75SAxel Dörfler License along with the GNU C Library; if not, write to the Free
16*5af32e75SAxel Dörfler Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17*5af32e75SAxel Dörfler 02111-1307 USA.
18*5af32e75SAxel Dörfler */
19*5af32e75SAxel Dörfler
20*5af32e75SAxel Dörfler
21*5af32e75SAxel Dörfler #include <stdio_private.h>
22*5af32e75SAxel Dörfler #include <errno.h>
23*5af32e75SAxel Dörfler #include <limits.h>
24*5af32e75SAxel Dörfler #include <printf.h>
25*5af32e75SAxel Dörfler #include <stddef.h>
26*5af32e75SAxel Dörfler #include <stdlib.h>
27*5af32e75SAxel Dörfler
28*5af32e75SAxel Dörfler
29*5af32e75SAxel Dörfler /* Array of functions indexed by format character. */
30*5af32e75SAxel Dörfler libc_freeres_ptr (printf_arginfo_function **__printf_arginfo_table)
31*5af32e75SAxel Dörfler attribute_hidden;
32*5af32e75SAxel Dörfler printf_function **__printf_function_table attribute_hidden;
33*5af32e75SAxel Dörfler
34*5af32e75SAxel Dörfler int __register_printf_function __P ((int, printf_function,
35*5af32e75SAxel Dörfler printf_arginfo_function));
36*5af32e75SAxel Dörfler
37*5af32e75SAxel Dörfler /* Register FUNC to be called to format SPEC specifiers. */
38*5af32e75SAxel Dörfler int
__register_printf_function(spec,converter,arginfo)39*5af32e75SAxel Dörfler __register_printf_function (spec, converter, arginfo)
40*5af32e75SAxel Dörfler int spec;
41*5af32e75SAxel Dörfler printf_function converter;
42*5af32e75SAxel Dörfler printf_arginfo_function arginfo;
43*5af32e75SAxel Dörfler {
44*5af32e75SAxel Dörfler if (spec < 0 || spec > (int) UCHAR_MAX)
45*5af32e75SAxel Dörfler {
46*5af32e75SAxel Dörfler __set_errno (EINVAL);
47*5af32e75SAxel Dörfler return -1;
48*5af32e75SAxel Dörfler }
49*5af32e75SAxel Dörfler
50*5af32e75SAxel Dörfler if (__printf_function_table == NULL)
51*5af32e75SAxel Dörfler {
52*5af32e75SAxel Dörfler __printf_arginfo_table = (printf_arginfo_function **)
53*5af32e75SAxel Dörfler malloc ((UCHAR_MAX + 1) * sizeof (void *) * 2);
54*5af32e75SAxel Dörfler if (__printf_arginfo_table == NULL)
55*5af32e75SAxel Dörfler return -1;
56*5af32e75SAxel Dörfler __printf_function_table = (printf_function **)
57*5af32e75SAxel Dörfler (__printf_arginfo_table + UCHAR_MAX + 1);
58*5af32e75SAxel Dörfler }
59*5af32e75SAxel Dörfler
60*5af32e75SAxel Dörfler __printf_function_table[spec] = converter;
61*5af32e75SAxel Dörfler __printf_arginfo_table[spec] = arginfo;
62*5af32e75SAxel Dörfler
63*5af32e75SAxel Dörfler return 0;
64*5af32e75SAxel Dörfler }
65*5af32e75SAxel Dörfler weak_alias (__register_printf_function, register_printf_function)
66