1 // The Musl sources for snprintf(), sscanf() assume they can use a specially 2 // crafted FILE object to represent the output/input buffers. However, this 3 // doesn't work when using FILE handle from Bionic. 4 // 5 // This header is used to 'cheat' by redefining FILE and a few other macro 6 // redefinitions for functions used in the sources in this directory. 7 8 #ifndef STDIO_IMPL_H 9 #define STDIO_IMPL_H 10 11 #define __HIDDEN__ __attribute__((__visibility__("hidden"))) 12 13 // A structure that wraps either a real FILE* handle, or an input/output 14 // buffer. 15 typedef struct { 16 FILE* file; 17 unsigned char* buffer; 18 size_t buffer_size; 19 size_t buffer_pos; 20 } FakeFILE; 21 22 // Initialize FakeFILE wrapper |file| to use a FILE* handle |f| 23 void fake_file_init_file(FakeFILE* file, FILE* f) __HIDDEN__; 24 25 // Initialize FakeFILE wrapper |file| to use a |buffer| of |buffer_size| chars. 26 void fake_file_init_buffer(FakeFILE* file, char* buffer, size_t buffer_size) 27 __HIDDEN__; 28 29 // Initialize FakeFILE wrapper |file| to use a wchar_t |buffer| of 30 // |buffer_size| wide-chars. 31 void fake_file_init_wbuffer(FakeFILE* file, wchar_t* buffer, size_t buffer_size) 32 __HIDDEN__; 33 34 // Replacement for out() in vfprintf.c 35 void fake_file_out(FakeFILE* file, const char* s, size_t l) __HIDDEN__; 36 37 // Replacement for out() in fvwprintf.c 38 void fake_file_outw(FakeFILE* file, const wchar_t* s, size_t l) __HIDDEN__; 39 40 // Fake replacement for stdio functions of similar names. 41 int fake_feof(FakeFILE* file) __HIDDEN__; 42 int fake_ferror(FakeFILE* file) __HIDDEN__; 43 int fake_fprintf(FakeFILE* file, const char* fmt, ...) __HIDDEN__; 44 void fake_fputc(char ch, FakeFILE* file) __HIDDEN__; 45 void fake_fputwc(wchar_t wc, FakeFILE* file) __HIDDEN__; 46 47 #ifndef _STDIO_IMPL_NO_REDIRECT_MACROS 48 49 // Macro redirection - ugly but necessary to minimize changes to the sources. 50 #define FILE FakeFILE 51 52 #undef feof 53 #define feof fake_feof 54 55 #undef ferror 56 #define ferror fake_ferror 57 #define fprintf fake_fprintf 58 #define fputc fake_fputc 59 #define fputwc fake_fputwc 60 61 #endif /* _STDIO_IMPL_NO_REDIRECT_MACROS */ 62 63 #endif /* STDIO_IMPL_H */ 64