diff options
| author | jvoisin | 2023-09-30 20:24:58 +0200 |
|---|---|---|
| committer | jvoisin | 2023-09-30 20:24:58 +0200 |
| commit | 76fef96b2b29fc90cdfea3e595ab98d267c6b965 (patch) | |
| tree | c3d5591a1782ec92ae2a9e9cf2739db681875841 | |
| parent | 160298c6fb4c5151ef58ef1556ae2c271d8a9a9e (diff) | |
Add `vprintf`
| -rw-r--r-- | include/stdio.h | 19 | ||||
| -rw-r--r-- | tests/Makefile | 1 | ||||
| -rw-r--r-- | tests/test_vprintf.c | 16 |
3 files changed, 35 insertions, 1 deletions
diff --git a/include/stdio.h b/include/stdio.h index e93fe19..9415f83 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -36,9 +36,10 @@ extern "C" { | |||
| 36 | #undef fread | 36 | #undef fread |
| 37 | #undef fwrite | 37 | #undef fwrite |
| 38 | #undef popen | 38 | #undef popen |
| 39 | #undef printf | ||
| 40 | #undef vprintf | ||
| 39 | #undef vsnprintf | 41 | #undef vsnprintf |
| 40 | #undef vsprintf | 42 | #undef vsprintf |
| 41 | #undef printf | ||
| 42 | 43 | ||
| 43 | __access(read_only, 2) | 44 | __access(read_only, 2) |
| 44 | #if __has_builtin(__builtin_fdopen) | 45 | #if __has_builtin(__builtin_fdopen) |
| @@ -183,6 +184,22 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | |||
| 183 | #endif | 184 | #endif |
| 184 | } | 185 | } |
| 185 | 186 | ||
| 187 | #ifndef __clang__ /* FIXME */ | ||
| 188 | __access(read_only, 1) | ||
| 189 | __format(printf, 1, 0) | ||
| 190 | #if __has_builtin(__builtin_vprintf) | ||
| 191 | __diagnose_as_builtin(__builtin_vprintf, 1, 2) | ||
| 192 | #endif | ||
| 193 | _FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v) | ||
| 194 | { | ||
| 195 | #if __has_builtin(__builtin___vprintf_chk) && USE_NATIVE_CHK | ||
| 196 | return __builtin___vprintf_chk(_FORTIFY_SOURCE, __f, __v); | ||
| 197 | #else | ||
| 198 | return __orig_vprintf(__f, __v); | ||
| 199 | #endif | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 186 | 203 | ||
| 187 | #if __has_builtin(__builtin_va_arg_pack) | 204 | #if __has_builtin(__builtin_va_arg_pack) |
| 188 | 205 | ||
diff --git a/tests/Makefile b/tests/Makefile index c862c52..4c127b5 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -113,6 +113,7 @@ RUNTIME_TARGETS= \ | |||
| 113 | test_vsnprintf_dynamic \ | 113 | test_vsnprintf_dynamic \ |
| 114 | test_vsnprintf_static \ | 114 | test_vsnprintf_static \ |
| 115 | test_vsprintf \ | 115 | test_vsprintf \ |
| 116 | test_vprintf \ | ||
| 116 | test_wcscat_static_write \ | 117 | test_wcscat_static_write \ |
| 117 | test_wcscpy_static_write \ | 118 | test_wcscpy_static_write \ |
| 118 | test_wcsncat_static_write \ | 119 | test_wcsncat_static_write \ |
diff --git a/tests/test_vprintf.c b/tests/test_vprintf.c new file mode 100644 index 0000000..e2e963e --- /dev/null +++ b/tests/test_vprintf.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <stdarg.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | void wrap(char *format, ...) { | ||
| 7 | va_list args; | ||
| 8 | va_start(args, format); | ||
| 9 | vprintf(format, args); | ||
| 10 | va_end(args); | ||
| 11 | } | ||
| 12 | |||
| 13 | |||
| 14 | int main(int argc, char** argv) { | ||
| 15 | wrap("%s", "1234567"); | ||
| 16 | } | ||
