1*61046927SAndroid Build Coastguard Worker // 2*61046927SAndroid Build Coastguard Worker // Copyright 2020 Serge Martin 3*61046927SAndroid Build Coastguard Worker // 4*61046927SAndroid Build Coastguard Worker // Permission is hereby granted, free of charge, to any person obtaining a 5*61046927SAndroid Build Coastguard Worker // copy of this software and associated documentation files (the "Software"), 6*61046927SAndroid Build Coastguard Worker // to deal in the Software without restriction, including without limitation 7*61046927SAndroid Build Coastguard Worker // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*61046927SAndroid Build Coastguard Worker // and/or sell copies of the Software, and to permit persons to whom the 9*61046927SAndroid Build Coastguard Worker // Software is furnished to do so, subject to the following conditions: 10*61046927SAndroid Build Coastguard Worker // 11*61046927SAndroid Build Coastguard Worker // The above copyright notice and this permission notice shall be included in 12*61046927SAndroid Build Coastguard Worker // all copies or substantial portions of the Software. 13*61046927SAndroid Build Coastguard Worker // 14*61046927SAndroid Build Coastguard Worker // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*61046927SAndroid Build Coastguard Worker // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*61046927SAndroid Build Coastguard Worker // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*61046927SAndroid Build Coastguard Worker // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*61046927SAndroid Build Coastguard Worker // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*61046927SAndroid Build Coastguard Worker // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*61046927SAndroid Build Coastguard Worker // OTHER DEALINGS IN THE SOFTWARE. 21*61046927SAndroid Build Coastguard Worker // 22*61046927SAndroid Build Coastguard Worker #ifndef U_PRINTF_H 23*61046927SAndroid Build Coastguard Worker #define U_PRINTF_H 24*61046927SAndroid Build Coastguard Worker 25*61046927SAndroid Build Coastguard Worker #include <stdarg.h> 26*61046927SAndroid Build Coastguard Worker #include <stddef.h> 27*61046927SAndroid Build Coastguard Worker #include <stdio.h> 28*61046927SAndroid Build Coastguard Worker 29*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus 30*61046927SAndroid Build Coastguard Worker extern "C" { 31*61046927SAndroid Build Coastguard Worker #endif 32*61046927SAndroid Build Coastguard Worker 33*61046927SAndroid Build Coastguard Worker typedef struct u_printf_info { 34*61046927SAndroid Build Coastguard Worker unsigned num_args; 35*61046927SAndroid Build Coastguard Worker unsigned *arg_sizes; 36*61046927SAndroid Build Coastguard Worker unsigned string_size; 37*61046927SAndroid Build Coastguard Worker char *strings; 38*61046927SAndroid Build Coastguard Worker } u_printf_info; 39*61046927SAndroid Build Coastguard Worker 40*61046927SAndroid Build Coastguard Worker const char *util_printf_prev_tok(const char *str); 41*61046927SAndroid Build Coastguard Worker 42*61046927SAndroid Build Coastguard Worker /* find next valid printf specifier in a C string wrapper */ 43*61046927SAndroid Build Coastguard Worker size_t util_printf_next_spec_pos(const char *str, size_t pos); 44*61046927SAndroid Build Coastguard Worker 45*61046927SAndroid Build Coastguard Worker /* Return the length of the string that would be generated by a printf-style 46*61046927SAndroid Build Coastguard Worker * format and argument list, not including the \0 byte. 47*61046927SAndroid Build Coastguard Worker * The untouched_args parameter is left untouched so it can be re-used by the 48*61046927SAndroid Build Coastguard Worker * caller in a vsnprintf() call or similar. 49*61046927SAndroid Build Coastguard Worker */ 50*61046927SAndroid Build Coastguard Worker size_t u_printf_length(const char *fmt, va_list untouched_args); 51*61046927SAndroid Build Coastguard Worker 52*61046927SAndroid Build Coastguard Worker void u_printf(FILE *out, const char *buffer, size_t buffer_size, 53*61046927SAndroid Build Coastguard Worker const u_printf_info*, unsigned info_size); 54*61046927SAndroid Build Coastguard Worker 55*61046927SAndroid Build Coastguard Worker void u_printf_ptr(FILE *out, const char *buffer, size_t buffer_size, 56*61046927SAndroid Build Coastguard Worker const u_printf_info **info, unsigned info_size); 57*61046927SAndroid Build Coastguard Worker 58*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus 59*61046927SAndroid Build Coastguard Worker } 60*61046927SAndroid Build Coastguard Worker #endif 61*61046927SAndroid Build Coastguard Worker 62*61046927SAndroid Build Coastguard Worker #endif 63