Skip to content

Commit 60f9f2e

Browse files
Eyal Rozenbergeyalroz
Eyal Rozenberg
authored andcommitted
Fixes #14: We now have a CMake build option, translated into a defined value, controlling whether or not to alias printf(), sprintf() etc.
1 parent 82b5978 commit 60f9f2e

File tree

3 files changed

+421
-408
lines changed

3 files changed

+421
-408
lines changed

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ if (NOT SUPPORT_PTRDIFF_ARGUMENTS)
2929
add_definitions(-DPRINTF_DISABLE_SUPPORT_PTRDIFF_T)
3030
endif()
3131

32+
option(ALIAS_STANDARD_FUNCTION_NAMES "Alias the relevant standard library function (printf, sprintf etc.) to the library's implementations" ON)
33+
if (NOT ALIAS_STANDARD_FUNCTION_NAMES)
34+
add_definitions(-DALIAS_STANDARD_FUNCTION_NAMES)
35+
endif()
36+
37+
option(ALIAS_STANDARD_FUNCTION_NAMES "Alias the relevant standard library function (printf, sprintf etc.) to the library's implementations" ON)
38+
if (NOT ALIAS_STANDARD_FUNCTION_NAMES)
39+
add_definitions(-DALIAS_STANDARD_FUNCTION_NAMES)
40+
endif()
41+
3242
# numeric defines
3343

3444
set(INTEGER_TO_STRING_BUFFER_SIZE "32" CACHE STRING "Integer to string (ntoa) conversion buffer size")

printf.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
4949
# define ATTR_VPRINTF(one_based_format_index)
5050
#endif
5151

52+
#ifdef ALIAS_STANDARD_FUNCTION_NAMES
53+
# define printf printf_
54+
# define sprintf sprintf_
55+
# define vsprintf vsprintf_
56+
# define snprintf snprintf_
57+
# define vsnprintf vsnprintf_
58+
# define vprintf vprintf_
59+
#endif
60+
5261

5362
/**
5463
* Output a character to a custom device like UART, used by the printf() function
@@ -66,7 +75,6 @@ void _putchar(char character);
6675
* \param format A string that specifies the format of the output
6776
* \return The number of characters that are written into the array, not counting the terminating null character
6877
*/
69-
#define printf printf_
7078
int printf_(const char* format, ...) ATTR_PRINTF(1, 2);
7179

7280

@@ -78,8 +86,6 @@ int printf_(const char* format, ...) ATTR_PRINTF(1, 2);
7886
* \param va A value identifying a variable arguments list
7987
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
8088
*/
81-
#define sprintf sprintf_
82-
#define vsprintf vsprintf_
8389
int sprintf_(char* buffer, const char* format, ...) ATTR_PRINTF(2, 3);
8490
int vsprintf_(char* buffer, const char* format, va_list va) ATTR_VPRINTF(2);
8591

@@ -94,8 +100,6 @@ int vsprintf_(char* buffer, const char* format, va_list va) ATTR_VPRINTF(2);
94100
* null character. A value equal or larger than count indicates truncation. Only when the returned value
95101
* is non-negative and less than count, the string has been completely written.
96102
*/
97-
#define snprintf snprintf_
98-
#define vsnprintf vsnprintf_
99103
int snprintf_(char* buffer, size_t count, const char* format, ...) ATTR_PRINTF(3, 4);
100104
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) ATTR_VPRINTF(3);
101105

@@ -106,7 +110,6 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) ATTR_
106110
* \param va A value identifying a variable arguments list
107111
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
108112
*/
109-
#define vprintf vprintf_
110113
int vprintf_(const char* format, va_list va) ATTR_VPRINTF(1);
111114

112115

0 commit comments

Comments
 (0)