1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* ****************************************************************************
* printf.h -- printf-related utilities.
*
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of the 'all/core' module in libcarrot, an experimental
* modular libc project.
*
* This file is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This file 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 Lesser General Lesser Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this file. If not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include <cdefs.h>
#include <stdio.h>
#include <stdarg.h>
__BEGIN_DECLS
/* ************************************************************************* */
/* Main printf utilities */
/* ************************************************************************* */
__BEGIN_NAMESPACE_STD
/* print in a string */
#if __USE_C89
extern __nonnull(1, __str) __nonnull(2, __fmt) __printf_format(2, 3)
int sprintf(char __str[__notnull], const char __fmt[__notnull], ...)
__THROW;
extern __nonnull(1, __str) __nonnull(3, __fmt) __printf_format(3, 4)
int snprintf(char __str[__notnull], size_t __size,
const char __fmt[__notnull], ...) __THROW;
#else
extern int sprintf() __THROW;
extern int snprintf() __THROW;
#endif
extern __nonnull(1, __str) __nonnull(2, __fmt)
int vsprintf _OF((char __str[__notnull], const char __fmt[__notnull],
va_list __ap)) __THROW;
extern __nonnull(1, __str) __nonnull(3, __fmt)
int vsnprintf _OF((char __str[__notnull], size_t __size,
const char __fmt[__notnull], va_list __ap)) __THROW;
/* print in a stream */
#if __USE_C89
extern __nonnull(1, __fmt) __printf_format(1, 2)
int printf(const char __fmt[__notnull], ...) __THROW;
extern __nonnull(2, __fmt) __printf_format(2, 3)
int fprintf(FILE *__stream, const char *__fmt, ...) __THROW;
#else
extern int printf() __THROW;
extern int fprintf() __THROW;
#endif
extern __nonnull(1, __fmt)
int vprintf _OF((const char __fmt[__notnull], va_list __ap)) __THROW;
extern __nonnull(2, __fmt)
int vfprintf _OF((FILE *__stream, const char __fmt[__notnull],
va_list __ap)) __THROW;
__END_NAMESPACE_STD
/* ************************************************************************* */
/* Callback utilities */
/* ************************************************************************* */
/* flags */
#define printf_flag_char 0x0001 /* 'hh' type modifier */
#define printf_flag_short 0x0002 /* 'h' type modifier */
#define printf_flag_long 0x0004 /* 'l' type modifier */
#define printf_flag_llong 0x0008 /* 'L', 'll' or 'q' type modifier */
#define printf_flag_size 0x0010 /* 'z' type modifier */
#define printf_flag_imax 0x0020 /* 'j' type modifier */
#define printf_flag_ptr 0x0040 /* 't' type modifier */
#define printf_flag_alt 0x0100 /* '#' flag */
#define printf_flag_space 0x0200 /* ' ' flag */
#define printf_flag_left 0x0400 /* '-' flag */
#define printf_flag_sign 0x0800 /* '+' flag */
#define printf_flag_grp 0x1000 /* "'" flag */
/* info */
typedef struct printf_info {
unsigned int flags;
int spec; /* original character */
int prec; /* precision, -1 if none specified */
int width; /* minimum field width, 0 if none specified */
int pad; /* character used for padding the output, '0' or ' ' */
} printf_t;
/* callback type */
typedef int printf_callback_t _OF((FILE*, printf_t*, va_list));
/* ************************************************************************* */
/* Interact with printf callbacks */
/* ************************************************************************* */
/* get a callback corresponding to a specifier */
extern __nonnull(2, __func)
int find_printf_function _OF((int __spec,
printf_callback_t *__func[__notnull])) __THROW;
/* set a callback for a specifier */
extern int register_printf_function _OF((int __spec,
printf_callback_t *__func)) __THROW;
/* reset the callbacks */
extern void reset_printf_functions _OF((void)) __THROW;
__END_DECLS
|