PIPS
printf-args.h File Reference
#include <stddef.h>
#include <stdarg.h>
+ Include dependency graph for printf-args.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  argument
 Polymorphic argument. More...
 
struct  arguments
 

Macros

#define PRINTF_FETCHARGS   printf_fetchargs
 Decomposed printf argument list. More...
 
#define N_DIRECT_ALLOC_ARGUMENTS   7
 Number of directly allocated arguments (no malloc() needed). More...
 

Enumerations

enum  arg_type {
  TYPE_NONE , TYPE_SCHAR , TYPE_UCHAR , TYPE_SHORT ,
  TYPE_USHORT , TYPE_INT , TYPE_UINT , TYPE_LONGINT ,
  TYPE_ULONGINT , TYPE_DOUBLE , TYPE_LONGDOUBLE , TYPE_CHAR ,
  TYPE_STRING , TYPE_POINTER , TYPE_COUNT_SCHAR_POINTER , TYPE_COUNT_SHORT_POINTER ,
  TYPE_COUNT_INT_POINTER , TYPE_COUNT_LONGINT_POINTER
}
 Get size_t. More...
 

Functions

int PRINTF_FETCHARGS (va_list args, arguments *a)
 Fetch the arguments, putting them into a. More...
 

Macro Definition Documentation

◆ N_DIRECT_ALLOC_ARGUMENTS

#define N_DIRECT_ALLOC_ARGUMENTS   7

Number of directly allocated arguments (no malloc() needed).


Definition at line 139 of file printf-args.h.

◆ PRINTF_FETCHARGS

#define PRINTF_FETCHARGS   printf_fetchargs

Decomposed printf argument list.

Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2014 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
This file can be parametrized with the following macros: ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. PRINTF_FETCHARGS Name of the function to be declared. STATIC Set to 'static' to declare the function static.
Default parameters.

Definition at line 28 of file printf-args.h.

Enumeration Type Documentation

◆ arg_type

enum arg_type

Get size_t.


Get wchar_t.
Get wint_t.
Get va_list.
Argument types

Enumerator
TYPE_NONE 
TYPE_SCHAR 
TYPE_UCHAR 
TYPE_SHORT 
TYPE_USHORT 
TYPE_INT 
TYPE_UINT 
TYPE_LONGINT 
TYPE_ULONGINT 
TYPE_DOUBLE 
TYPE_LONGDOUBLE 
TYPE_CHAR 
TYPE_STRING 
TYPE_POINTER 
TYPE_COUNT_SCHAR_POINTER 
TYPE_COUNT_SHORT_POINTER 
TYPE_COUNT_INT_POINTER 
TYPE_COUNT_LONGINT_POINTER 

Definition at line 49 of file printf-args.h.

50 {
51  TYPE_NONE,
52  TYPE_SCHAR,
53  TYPE_UCHAR,
54  TYPE_SHORT,
56  TYPE_INT,
57  TYPE_UINT,
60 #if HAVE_LONG_LONG_INT
61  TYPE_LONGLONGINT,
62  TYPE_ULONGLONGINT,
63 #endif
66  TYPE_CHAR,
67 #if HAVE_WINT_T
68  TYPE_WIDE_CHAR,
69 #endif
71 #if HAVE_WCHAR_T
72  TYPE_WIDE_STRING,
73 #endif
79 #if HAVE_LONG_LONG_INT
80 , TYPE_COUNT_LONGLONGINT_POINTER
81 #endif
82 #if ENABLE_UNISTDIO
83  /* The unistdio extensions. */
84 , TYPE_U8_STRING
85 , TYPE_U16_STRING
86 , TYPE_U32_STRING
87 #endif
88 } arg_type;
arg_type
Get size_t.
Definition: printf-args.h:50
@ TYPE_DOUBLE
Definition: printf-args.h:64
@ TYPE_NONE
Definition: printf-args.h:51
@ TYPE_SHORT
Definition: printf-args.h:54
@ TYPE_CHAR
Definition: printf-args.h:66
@ TYPE_USHORT
Definition: printf-args.h:55
@ TYPE_INT
Definition: printf-args.h:56
@ TYPE_LONGINT
Definition: printf-args.h:58
@ TYPE_COUNT_SCHAR_POINTER
Definition: printf-args.h:75
@ TYPE_POINTER
Definition: printf-args.h:74
@ TYPE_SCHAR
Definition: printf-args.h:52
@ TYPE_LONGDOUBLE
Definition: printf-args.h:65
@ TYPE_COUNT_SHORT_POINTER
Definition: printf-args.h:76
@ TYPE_COUNT_LONGINT_POINTER
Definition: printf-args.h:78
@ TYPE_COUNT_INT_POINTER
Definition: printf-args.h:77
@ TYPE_UINT
Definition: printf-args.h:57
@ TYPE_ULONGINT
Definition: printf-args.h:59
@ TYPE_STRING
Definition: printf-args.h:70
@ TYPE_UCHAR
Definition: printf-args.h:53

Function Documentation

◆ PRINTF_FETCHARGS()

int PRINTF_FETCHARGS ( va_list  args,
arguments a 
)

Fetch the arguments, putting them into a.

Fetch the arguments, putting them into a.

Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2014 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/.
This file can be parametrized with the following macros: ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. PRINTF_FETCHARGS Name of the function to be defined. STATIC Set to 'static' to declare the function static.
Specification.

igned char

nsigned char

hort

nsigned short

A null pointer is an invalid argument for "%s", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case.

Unknown type.

Definition at line 36 of file printf-args.c.

37 {
38  size_t i;
39  argument *ap;
40 
41  for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
42  switch (ap->type)
43  {
44  case TYPE_SCHAR:
45  ap->a.a_schar = va_arg (args, /*signed char*/ int);
46  break;
47  case TYPE_UCHAR:
48  ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
49  break;
50  case TYPE_SHORT:
51  ap->a.a_short = va_arg (args, /*short*/ int);
52  break;
53  case TYPE_USHORT:
54  ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
55  break;
56  case TYPE_INT:
57  ap->a.a_int = va_arg (args, int);
58  break;
59  case TYPE_UINT:
60  ap->a.a_uint = va_arg (args, unsigned int);
61  break;
62  case TYPE_LONGINT:
63  ap->a.a_longint = va_arg (args, long int);
64  break;
65  case TYPE_ULONGINT:
66  ap->a.a_ulongint = va_arg (args, unsigned long int);
67  break;
68 #if HAVE_LONG_LONG_INT
69  case TYPE_LONGLONGINT:
70  ap->a.a_longlongint = va_arg (args, long long int);
71  break;
72  case TYPE_ULONGLONGINT:
73  ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
74  break;
75 #endif
76  case TYPE_DOUBLE:
77  ap->a.a_double = va_arg (args, double);
78  break;
79  case TYPE_LONGDOUBLE:
80  ap->a.a_longdouble = va_arg (args, long double);
81  break;
82  case TYPE_CHAR:
83  ap->a.a_char = va_arg (args, int);
84  break;
85 #if HAVE_WINT_T
86  case TYPE_WIDE_CHAR:
87  /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
88  default argument promotions", this is not the case in mingw32,
89  where wint_t is 'unsigned short'. */
90  ap->a.a_wide_char =
91  (sizeof (wint_t) < sizeof (int)
92  ? (wint_t) va_arg (args, int)
93  : va_arg (args, wint_t));
94  break;
95 #endif
96  case TYPE_STRING:
97  ap->a.a_string = va_arg (args, const char *);
98  /* A null pointer is an invalid argument for "%s", but in practice
99  it occurs quite frequently in printf statements that produce
100  debug output. Use a fallback in this case. */
101  if (ap->a.a_string == NULL)
102  ap->a.a_string = "(NULL)";
103  break;
104 #if HAVE_WCHAR_T
105  case TYPE_WIDE_STRING:
106  ap->a.a_wide_string = va_arg (args, const wchar_t *);
107  /* A null pointer is an invalid argument for "%ls", but in practice
108  it occurs quite frequently in printf statements that produce
109  debug output. Use a fallback in this case. */
110  if (ap->a.a_wide_string == NULL)
111  {
112  static const wchar_t wide_null_string[] =
113  {
114  (wchar_t)'(',
115  (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
116  (wchar_t)')',
117  (wchar_t)0
118  };
119  ap->a.a_wide_string = wide_null_string;
120  }
121  break;
122 #endif
123  case TYPE_POINTER:
124  ap->a.a_pointer = va_arg (args, void *);
125  break;
127  ap->a.a_count_schar_pointer = va_arg (args, signed char *);
128  break;
130  ap->a.a_count_short_pointer = va_arg (args, short *);
131  break;
133  ap->a.a_count_int_pointer = va_arg (args, int *);
134  break;
136  ap->a.a_count_longint_pointer = va_arg (args, long int *);
137  break;
138 #if HAVE_LONG_LONG_INT
139  case TYPE_COUNT_LONGLONGINT_POINTER:
140  ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
141  break;
142 #endif
143 #if ENABLE_UNISTDIO
144  /* The unistdio extensions. */
145  case TYPE_U8_STRING:
146  ap->a.a_u8_string = va_arg (args, const uint8_t *);
147  /* A null pointer is an invalid argument for "%U", but in practice
148  it occurs quite frequently in printf statements that produce
149  debug output. Use a fallback in this case. */
150  if (ap->a.a_u8_string == NULL)
151  {
152  static const uint8_t u8_null_string[] =
153  { '(', 'N', 'U', 'L', 'L', ')', 0 };
154  ap->a.a_u8_string = u8_null_string;
155  }
156  break;
157  case TYPE_U16_STRING:
158  ap->a.a_u16_string = va_arg (args, const uint16_t *);
159  /* A null pointer is an invalid argument for "%lU", but in practice
160  it occurs quite frequently in printf statements that produce
161  debug output. Use a fallback in this case. */
162  if (ap->a.a_u16_string == NULL)
163  {
164  static const uint16_t u16_null_string[] =
165  { '(', 'N', 'U', 'L', 'L', ')', 0 };
166  ap->a.a_u16_string = u16_null_string;
167  }
168  break;
169  case TYPE_U32_STRING:
170  ap->a.a_u32_string = va_arg (args, const uint32_t *);
171  /* A null pointer is an invalid argument for "%llU", but in practice
172  it occurs quite frequently in printf statements that produce
173  debug output. Use a fallback in this case. */
174  if (ap->a.a_u32_string == NULL)
175  {
176  static const uint32_t u32_null_string[] =
177  { '(', 'N', 'U', 'L', 'L', ')', 0 };
178  ap->a.a_u32_string = u32_null_string;
179  }
180  break;
181 #endif
182  default:
183  /* Unknown type. */
184  return -1;
185  }
186  return 0;
187 }
static int count
Definition: SDG.c:519
#define wchar_t
On NetBSD 5.0, the definition of NULL lacks proper parentheses.
Definition: stddef.in.h:82
#define uint32_t
Definition: stdint.in.h:156
#define uint16_t
Definition: stdint.in.h:149
#define uint8_t
Definition: stdint.in.h:142
Polymorphic argument.
Definition: printf-args.h:92
int a_char
Definition: printf-args.h:111
signed char * a_count_schar_pointer
Definition: printf-args.h:120
unsigned int a_uint
Definition: printf-args.h:101
long int * a_count_longint_pointer
Definition: printf-args.h:123
arg_type type
Definition: printf-args.h:93
signed char a_schar
Definition: printf-args.h:96
unsigned long int a_ulongint
Definition: printf-args.h:103
long double a_longdouble
Definition: printf-args.h:110
short a_short
Definition: printf-args.h:98
double a_double
Definition: printf-args.h:109
unsigned short a_ushort
Definition: printf-args.h:99
unsigned char a_uchar
Definition: printf-args.h:97
union argument::@14 a
const char * a_string
Definition: printf-args.h:115
long int a_longint
Definition: printf-args.h:102
void * a_pointer
Definition: printf-args.h:119
short * a_count_short_pointer
Definition: printf-args.h:121
int * a_count_int_pointer
Definition: printf-args.h:122
argument * arg
Definition: printf-args.h:144
#define wint_t
The definitions of _GL_FUNCDECL_RPL etc.
Definition: wchar.in.h:103

References argument::a, argument::a_char, argument::a_count_int_pointer, argument::a_count_longint_pointer, argument::a_count_schar_pointer, argument::a_count_short_pointer, argument::a_double, argument::a_int, argument::a_longdouble, argument::a_longint, argument::a_pointer, argument::a_schar, argument::a_short, argument::a_string, argument::a_uchar, argument::a_uint, argument::a_ulongint, argument::a_ushort, arguments::arg, count, argument::type, TYPE_CHAR, TYPE_COUNT_INT_POINTER, TYPE_COUNT_LONGINT_POINTER, TYPE_COUNT_SCHAR_POINTER, TYPE_COUNT_SHORT_POINTER, TYPE_DOUBLE, TYPE_INT, TYPE_LONGDOUBLE, TYPE_LONGINT, TYPE_POINTER, TYPE_SCHAR, TYPE_SHORT, TYPE_STRING, TYPE_UCHAR, TYPE_UINT, TYPE_ULONGINT, TYPE_USHORT, uint16_t, uint32_t, uint8_t, wchar_t, and wint_t.