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
|
/*
Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
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 of the License, 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/>.
*/
#ifndef WOLF_STDIO_H
#define WOLF_STDIO_H
/**
* @addtogroup wolf_port Porting
* @{
*/
/**
* @file stdio.h
* @brief nivelate things found in stdio.h, mostly snprintf's
* @author Andreas Baumann <abaumann@yahoo.com>
*/
#include "port/sys.h"
#include <stdio.h>
/* snprintf: a disaster, there are several versions out there. They
* differ in:
* - what they return: BSD and C99 stipulates the number of character which
* would be needed to map the whole string (which is the version we must
* stick to). Some other versions return -1 and ERANGE/EOVERFLOW in the
* the case of an overflow (notably older GNU C libraries)
* - what format string options they support:
* - some older Sun snprintf's were famous for being wrong in the floating
* point format placeholders
* - if they work at all (for instance sprintf_s on Windows 32k happily
* crashes the runnig process)! Also some older Solaris versions are
* known to have terrible bugs.
*/
/* TODO: check which features we need in snprintf, make sure the platform one supports it,
* otherwise we take the stub */
/* TODO: also clean up mess here with autoconf relicts! */
#if defined _WIN32
/* secure snprintf on Wndows is called differently, but not working
* we don't take sprintf_s
*/
#endif
#include <stdarg.h> /* for va_list */
#include <sys/types.h> /* for size_t */
#if !defined HAVE_SNPRINTF || defined WOLF_TEST_SNPRINTF
int rpl_snprintf( char *str, size_t size, const char *format, ... );
#endif /* !defined HAVE_SNPRINTF || defined TEST_SNPRINTF */
#if !defined HAVE_SNPRINTF
/* TODO: with variadic macros, we can define a much better macro here! */
#define snprintf rpl_snprintf
#endif /* !defined HAVE_SNPRINTF */
#if !defined HAVE_VSNPRINTF || defined WOLF_TEST_VSNPRINTF
int rpl_vsnprintf( char *str, size_t size, const char *format, va_list args );
#endif /* !defined HAVE_VSNPRINTF || defined TEST_VSNPRINTF */
#if !defined HAVE_VSNPRINTF
#define vsnprintf( str, size, format, ap ) rpl_vsnprintf( str, size, format, ap )
#endif /* !defined HAVE_VSNPRINTF */
/** @} */ /* @addtogroup wolf_port */
#endif /* ifndef WOLF_STDIO_H */
|