1
1
/* Formatted output to strings.
2
Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc.
2
Copyright (C) 1999-2000, 2002-2003, 2006-2007 Free Software Foundation, Inc.
4
4
This program is free software; you can redistribute it and/or modify it
5
5
under the terms of the GNU Library General Public License as published
14
14
You should have received a copy of the GNU Library General Public
15
15
License along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
/* This file can be parametrized with the following macros:
20
CHAR_T The element type of the format string.
21
CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
22
in the format string are ASCII.
23
DIRECTIVE Structure denoting a format directive.
25
DIRECTIVES Structure denoting the set of format directives of a
26
format string. Depends on CHAR_T.
27
PRINTF_PARSE Function that parses a format string.
29
STATIC Set to 'static' to declare the function static.
30
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
20
33
# include <config.h>
23
36
/* Specification. */
25
# include "wprintf-parse.h"
27
38
# include "printf-parse.h"
41
/* Default parameters. */
43
# define PRINTF_PARSE printf_parse
45
# define DIRECTIVE char_directive
46
# define DIRECTIVES char_directives
30
49
/* Get size_t, NULL. */
31
50
#include <stddef.h>
33
52
/* Get intmax_t. */
34
#if HAVE_STDINT_H_WITH_UINTMAX
53
#if defined IN_LIBINTL || defined IN_LIBASPRINTF
54
# if HAVE_STDINT_H_WITH_UINTMAX
57
# if HAVE_INTTYPES_H_WITH_UINTMAX
58
# include <inttypes.h>
35
61
# include <stdint.h>
37
#if HAVE_INTTYPES_H_WITH_UINTMAX
38
# include <inttypes.h>
41
64
/* malloc(), realloc(), free(). */
42
65
#include <stdlib.h>
44
70
/* Checked size_t computations. */
48
# define PRINTF_PARSE wprintf_parse
49
# define CHAR_T wchar_t
50
# define DIRECTIVE wchar_t_directive
51
# define DIRECTIVES wchar_t_directives
53
# define PRINTF_PARSE printf_parse
55
# define DIRECTIVE char_directive
56
# define DIRECTIVES char_directives
94
113
memory_size = xtimes (a_allocated, sizeof (argument)); \
95
114
if (size_overflow_p (memory_size)) \
96
115
/* Overflow, would lead to out of memory. */ \
99
? realloc (a->arg, memory_size) \
100
: malloc (memory_size)); \
116
goto out_of_memory; \
117
memory = (argument *) (a->arg \
118
? realloc (a->arg, memory_size) \
119
: malloc (memory_size)); \
101
120
if (memory == NULL) \
102
121
/* Out of memory. */ \
122
goto out_of_memory; \
104
123
a->arg = memory; \
106
125
while (a->count <= n) \
402
422
case 'o': case 'u': case 'x': case 'X':
403
#ifdef HAVE_LONG_LONG
423
#if HAVE_LONG_LONG_INT
424
/* If 'long long' exists and is larger than 'long': */
404
425
if (flags >= 16 || (flags & 4))
405
426
type = TYPE_ULONGLONGINT;
429
/* If 'unsigned long long' exists and is the same as
430
'unsigned long', we parse "llu" into TYPE_ULONGINT. */
409
432
type = TYPE_ULONGINT;
410
433
else if (flags & 2)
459
480
type = TYPE_POINTER;
462
#ifdef HAVE_LONG_LONG
483
#if HAVE_LONG_LONG_INT
484
/* If 'long long' exists and is larger than 'long': */
463
485
if (flags >= 16 || (flags & 4))
464
486
type = TYPE_COUNT_LONGLONGINT_POINTER;
489
/* If 'long long' exists and is the same as 'long', we parse
490
"lln" into TYPE_COUNT_LONGINT_POINTER. */
468
492
type = TYPE_COUNT_LONGINT_POINTER;
469
493
else if (flags & 2)
508
543
memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
509
544
if (size_overflow_p (memory_size))
510
545
/* Overflow, would lead to out of memory. */
512
memory = realloc (d->dir, memory_size);
547
memory = (DIRECTIVE *) realloc (d->dir, memory_size);
513
548
if (memory == NULL)
514
549
/* Out of memory. */
554
#if CHAR_T_ONLY_ASCII
555
else if (!c_isascii (c))
557
/* Non-ASCII character. Not supported. */
520
562
d->dir[d->count].dir_start = cp;