1/*- 2 * Copyright (c) 2005 Poul-Henning Kamp 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: src/include/printf.h,v 1.5 2011/03/06 17:45:37 pjd Exp $ 27 */ 28 29#ifndef _XPRINTF_PRIVATE_H_ 30#define _XPRINTF_PRIVATE_H_ 31 32#include <printf.h> 33#include <pthread.h> 34 35#ifndef VECTORS 36#define VECTORS 37typedef __attribute__ ((vector_size(16))) unsigned char VECTORTYPE; 38#ifdef __SSE2__ 39#define V64TYPE 40#endif /* __SSE2__ */ 41#endif /* !VECTORS */ 42 43/* FreeBSD extension */ 44struct __printf_io; 45typedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *); 46 47#if 0 48int register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo); 49#endif 50 51/* 52 * Unlike register_printf_domain_function(), register_printf_domain_render() 53 * doesn't have a context pointer, because none of the internal rendering 54 * functions use it. 55 */ 56int register_printf_domain_render(printf_domain_t, int, printf_render *, printf_arginfo_function *); 57 58/* xprintf.c */ 59extern const char __lowercase_hex[17]; 60extern const char __uppercase_hex[17]; 61 62void __printf_flush(struct __printf_io *io); 63int __printf_puts(struct __printf_io *io, const void *ptr, int len); 64int __printf_pad(struct __printf_io *io, int n, int zero); 65int __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len); 66 67int __v2printf(printf_comp_t restrict pc, printf_domain_t restrict domain, FILE * restrict fp, locale_t restrict loc, const char * restrict fmt0, va_list ap); 68int __xvprintf(printf_comp_t restrict pc, printf_domain_t restrict domain, FILE * restrict fp, locale_t restrict loc, const char * restrict fmt0, va_list ap); 69extern int __use_xprintf; 70 71printf_arginfo_function __printf_arginfo_pct; 72printf_render __printf_render_pct; 73 74printf_arginfo_function __printf_arginfo_n; 75printf_function __printf_render_n; 76 77#ifdef VECTORS 78printf_render __xprintf_vector; 79#endif /* VECTORS */ 80 81#ifdef XPRINTF_PERF 82#define CALLOC(x,y) xprintf_calloc((x),(y)) 83#define MALLOC(x) xprintf_malloc((x)) 84void *xprintf_calloc(size_t, size_t) __attribute__((__malloc__)); 85void *xprintf_malloc(size_t) __attribute__((__malloc__)); 86#else /* !XPRINTF_PERF */ 87#define CALLOC(x,y) calloc((x),(y)) 88#define MALLOC(x) malloc((x)) 89#endif /* !XPRINTF_PERF */ 90 91/* xprintf_domain.c */ 92void __xprintf_domain_init(void); 93extern pthread_once_t __xprintf_domain_once; 94#ifdef XPRINTF_DEBUG 95extern printf_domain_t xprintf_domain_global; 96#endif 97#ifdef XPRINTF_PERF 98struct array; /* forward reference */ 99void arrayfree(struct array *); 100#endif 101 102#define xprintf_domain_init() pthread_once(&__xprintf_domain_once, __xprintf_domain_init) 103 104/* xprintf_errno.c */ 105printf_arginfo_function __printf_arginfo_errno; 106printf_render __printf_render_errno; 107 108/* xprintf_float.c */ 109printf_arginfo_function __printf_arginfo_float; 110printf_render __printf_render_float; 111 112/* xprintf_hexdump.c */ 113printf_arginfo_function __printf_arginfo_hexdump; 114printf_render __printf_render_hexdump; 115 116/* xprintf_int.c */ 117printf_arginfo_function __printf_arginfo_ptr; 118printf_arginfo_function __printf_arginfo_int; 119printf_render __printf_render_ptr; 120printf_render __printf_render_int; 121 122/* xprintf_quoute.c */ 123printf_arginfo_function __printf_arginfo_quote; 124printf_render __printf_render_quote; 125 126/* xprintf_str.c */ 127printf_arginfo_function __printf_arginfo_chr; 128printf_render __printf_render_chr; 129printf_arginfo_function __printf_arginfo_str; 130printf_render __printf_render_str; 131 132/* xprintf_time.c */ 133printf_arginfo_function __printf_arginfo_time; 134printf_render __printf_render_time; 135 136/* xprintf_vis.c */ 137printf_arginfo_function __printf_arginfo_vis; 138printf_render __printf_render_vis; 139 140#ifdef XPRINTF_PERF 141struct array; /* forward reference */ 142#endif /* XPRINTF_PERF */ 143struct _printf_compiled { 144 pthread_mutex_t mutex; 145#ifdef XPRINTF_PERF 146 struct array *aa; 147 struct array *pa; 148 struct array *ua; 149#endif /* XPRINTF_PERF */ 150 const char *fmt; 151 printf_domain_t domain; 152 locale_t loc; 153 struct printf_info *pi; 154 struct printf_info *pil; 155 int *argt; 156 union arg *args; 157 int maxarg; 158}; 159 160#define XPRINTF_PLAIN ((printf_comp_t)-1) 161 162int __printf_comp(printf_comp_t restrict, printf_domain_t restrict); 163int __printf_exec(printf_comp_t restrict, FILE * restrict, va_list); 164 165#ifdef XPRINTF_PERF 166void arg_type_enqueue(struct array *); 167void print_info_enqueue(struct array *); 168void union_arg_enqueue(struct array *); 169#endif /* XPRINTF_PERF */ 170 171#endif /* !_XPRINTF_PRIVATE_H_ */ 172