1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 7 * 8 * See the COPYRIGHT file distributed with this work for additional 9 * information regarding copyright ownership. 10 */ 11 12 #ifndef LWRES_PRINT_P_H 13 #define LWRES_PRINT_P_H 1 14 15 /*** 16 *** Imports 17 ***/ 18 19 #include <lwres/lang.h> 20 #include <lwres/platform.h> 21 22 /* 23 * This block allows lib/lwres/print.c to be cleanly compiled even if 24 * the platform does not need it. The standard Makefile will still 25 * not compile print.c or archive print.o, so this is just to make test 26 * compilation ("make print.o") easier. 27 */ 28 #if !defined(LWRES_PLATFORM_NEEDVSNPRINTF) && defined(LWRES__PRINT_SOURCE) 29 #define LWRES_PLATFORM_NEEDVSNPRINTF 30 #endif 31 32 #if !defined(LWRES_PLATFORM_NEEDSPRINTF) && defined(LWRES__PRINT_SOURCE) 33 #define LWRES_PLATFORM_NEEDSPRINTF 34 #endif 35 36 /*** 37 *** Macros. 38 ***/ 39 40 #ifdef __GNUC__ 41 #define LWRES_FORMAT_PRINTF(fmt, args) \ 42 __attribute__((__format__(__printf__, fmt, args))) 43 #else 44 #define LWRES_FORMAT_PRINTF(fmt, args) 45 #endif 46 47 /*** 48 *** Functions 49 ***/ 50 51 #ifdef LWRES_PLATFORM_NEEDVSNPRINTF 52 #include <stdarg.h> 53 #include <stddef.h> 54 #endif 55 56 LWRES_LANG_BEGINDECLS 57 58 #ifdef LWRES_PLATFORM_NEEDVSNPRINTF 59 int 60 lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) 61 LWRES_FORMAT_PRINTF(3, 0); 62 #ifdef vsnprintf 63 #undef vsnprintf 64 #endif 65 #define vsnprintf lwres__print_vsnprintf 66 67 int 68 lwres__print_snprintf(char *str, size_t size, const char *format, ...) 69 LWRES_FORMAT_PRINTF(3, 4); 70 #ifdef snprintf 71 #undef snprintf 72 #endif 73 #define snprintf lwres__print_snprintf 74 #endif /* LWRES_PLATFORM_NEEDVSNPRINTF */ 75 76 #ifdef LWRES_PLATFORM_NEEDSPRINTF 77 int 78 lwres__print_sprintf(char *str, const char *format, ...) LWRES_FORMAT_PRINTF(2, 3); 79 #ifdef sprintf 80 #undef sprintf 81 #endif 82 #define sprintf lwres__print_sprintf 83 #endif 84 85 LWRES_LANG_ENDDECLS 86 87 #endif /* LWRES_PRINT_P_H */ 88