|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#ifdef FF_USE_STBPRINTF |
| 4 | + |
| 5 | +#include <stdio.h> |
| 6 | +#include <stdint.h> |
| 7 | +#include "3rdparty/stb/stb_sprintf.h" |
| 8 | + |
| 9 | +static inline char *STB_SPRINTF_DECORATE(printf_callback)(const char* __restrict buf, void* __restrict user, int len) |
| 10 | +{ |
| 11 | + fwrite(buf, 1, (uint32_t) len, (FILE *)user); |
| 12 | + return (char *) buf; |
| 13 | +} |
| 14 | + |
| 15 | +static inline int STB_SPRINTF_DECORATE(vfprintf)(FILE* file, char const* __restrict fmt, va_list va) |
| 16 | +{ |
| 17 | + char tmp[STB_SPRINTF_MIN]; |
| 18 | + return STB_SPRINTF_DECORATE(vsprintfcb)(STB_SPRINTF_DECORATE(printf_callback), file, tmp, fmt, va); |
| 19 | +} |
| 20 | +#define vfprintf(...) STB_SPRINTF_DECORATE(vfprintf)(__VA_ARGS__) |
| 21 | + |
| 22 | +static inline int STBSP__ATTRIBUTE_FORMAT(1,2) STB_SPRINTF_DECORATE(printf)(char const* __restrict fmt, ...) |
| 23 | +{ |
| 24 | + va_list va; |
| 25 | + va_start(va, fmt); |
| 26 | + int result = STB_SPRINTF_DECORATE(vfprintf)(stdout, fmt, va); |
| 27 | + va_end(va); |
| 28 | + return result; |
| 29 | +} |
| 30 | +#define printf(...) STB_SPRINTF_DECORATE(printf)(__VA_ARGS__) |
| 31 | + |
| 32 | +static inline int STBSP__ATTRIBUTE_FORMAT(2,3) STB_SPRINTF_DECORATE(fprintf)(FILE* __restrict file, char const* __restrict fmt, ...) |
| 33 | +{ |
| 34 | + va_list va; |
| 35 | + va_start(va, fmt); |
| 36 | + int result = STB_SPRINTF_DECORATE(vfprintf)(file, fmt, va); |
| 37 | + va_end(va); |
| 38 | + return result; |
| 39 | +} |
| 40 | +#define fprintf(...) STB_SPRINTF_DECORATE(fprintf)(__VA_ARGS__) |
| 41 | + |
| 42 | +#define vsprintf(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__) |
| 43 | + |
| 44 | +#define vsnprintf(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__) |
| 45 | + |
| 46 | +#define sprintf(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__) |
| 47 | + |
| 48 | +#define snprintf(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__) |
| 49 | + |
| 50 | +#endif |
0 commit comments