1 /* @(#)fprformat.c	1.4 16/01/18 Copyright 2013-2016 J. Schilling */
2 /*
3  *	fprformat
4  *	common code for printf fprintf & sprintf
5  *	This is the variant that uses stdio und directly calls putc.
6  *	If putc() is a FILE * derived macro, then a printf() based on this
7  * 	variant is faster than a format() based printf that needs to call a
8  *	function for every character in the output.
9  *
10  *	allows recursive printf with "%r", used in:
11  *	error, comerr, comerrno, errmsg, errmsgno and the like
12  *
13  *	Copyright (c) 2013-2016 J. Schilling
14  */
15 /*
16  * The contents of this file are subject to the terms of the
17  * Common Development and Distribution License, Version 1.0 only
18  * (the "License").  You may not use this file except in compliance
19  * with the License.
20  *
21  * See the file CDDL.Schily.txt in this distribution for details.
22  * A copy of the CDDL is also available via the Internet at
23  * http://www.opensource.org/licenses/cddl1.txt
24  *
25  * When distributing Covered Code, include this CDDL HEADER in each
26  * file and include the License file CDDL.Schily.txt from this distribution.
27  */
28 
29 #include <schily/mconfig.h>
30 #include <schily/varargs.h>
31 #include <schily/string.h>
32 #include <schily/stdlib.h>
33 #ifdef	DEBUG
34 #include <schily/unistd.h>
35 #endif
36 #include <schily/standard.h>
37 #include <schily/utypes.h>
38 #define	__EXTENSIONS__		/* Enable putc_unlocked() macro on Solaris */
39 #define	FAST_GETC_PUTC		/* Enable stdio extensions in schily/stdio.h */
40 #include <schily/stdio.h>
41 #include <schily/schily.h>	/* Must be past stdio.h */
42 
43 #define	FORMAT_FUNC_NAME	fprformat
44 #define	FORMAT_FUNC_PROTO_DECL
45 #define	FORMAT_FUNC_KR_DECL
46 #define	FORMAT_FUNC_KR_ARGS
47 #undef	FORMAT_FUNC_PARM
48 #ifdef	HAVE_PUTC_UNLOCKED
49 #define	ofun(c, fp)		putc_unlocked(c, (FILE *)fp)
50 #else
51 #define	ofun(c, fp)		putc(c, (FILE *)fp)
52 #endif
53 
54 /*
55  * If enabled, an internally buffered version of fprformat() is implemented
56  * that avoids completely unbuffered printing on onubuffered FILE pointers.
57  * This is 15% slower than the version that directly calls putc_unlocked()
58  * but it works on any OS.
59  */
60 #define	FORMAT_BUFFER
61 
62 #include "format.c"
63