Deleted Added
full compact
printfcommon.h (187284) printfcommon.h (187354)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: head/lib/libc/stdio/printfcommon.h 187284 2009-01-15 04:49:43Z das $
32 * $FreeBSD: head/lib/libc/stdio/printfcommon.h 187354 2009-01-17 05:38:14Z das $
33 */
34
35/*
36 * This file defines common routines used by both printf and wprintf.
37 * You must define CHAR to either char or wchar_t prior to including this.
38 */
39
40

--- 18 unchanged lines hidden (view full) ---

59static CHAR *__ultoa(u_long, CHAR *, int, int, const char *, int, char,
60 const char *);
61
62#define NIOV 8
63struct io_state {
64 FILE *fp;
65 struct __suio uio; /* output information: summary */
66 struct __siov iov[NIOV];/* ... and individual io vectors */
33 */
34
35/*
36 * This file defines common routines used by both printf and wprintf.
37 * You must define CHAR to either char or wchar_t prior to including this.
38 */
39
40

--- 18 unchanged lines hidden (view full) ---

59static CHAR *__ultoa(u_long, CHAR *, int, int, const char *, int, char,
60 const char *);
61
62#define NIOV 8
63struct io_state {
64 FILE *fp;
65 struct __suio uio; /* output information: summary */
66 struct __siov iov[NIOV];/* ... and individual io vectors */
67 struct __siov *iovp; /* pointer to next free slot in iov */
68};
69
70static inline void
71io_init(struct io_state *iop, FILE *fp)
72{
73
67};
68
69static inline void
70io_init(struct io_state *iop, FILE *fp)
71{
72
74 iop->uio.uio_iov = iop->iovp = iop->iov;
73 iop->uio.uio_iov = iop->iov;
75 iop->uio.uio_resid = 0;
76 iop->uio.uio_iovcnt = 0;
77 iop->fp = fp;
78}
79
80/*
81 * WARNING: The buffer passed to io_print() is not copied immediately; it must
82 * remain valid until io_flush() is called.
83 */
84static inline int
85io_print(struct io_state *iop, const CHAR * __restrict ptr, int len)
86{
87
74 iop->uio.uio_resid = 0;
75 iop->uio.uio_iovcnt = 0;
76 iop->fp = fp;
77}
78
79/*
80 * WARNING: The buffer passed to io_print() is not copied immediately; it must
81 * remain valid until io_flush() is called.
82 */
83static inline int
84io_print(struct io_state *iop, const CHAR * __restrict ptr, int len)
85{
86
88 iop->iovp->iov_base = (char *)ptr;
89 iop->iovp->iov_len = len;
87 iop->iov[iop->uio.uio_iovcnt].iov_base = (char *)ptr;
88 iop->iov[iop->uio.uio_iovcnt].iov_len = len;
90 iop->uio.uio_resid += len;
89 iop->uio.uio_resid += len;
91 iop->iovp++;
92 if (++iop->uio.uio_iovcnt >= NIOV) {
93 iop->iovp = iop->iov;
90 if (++iop->uio.uio_iovcnt >= NIOV)
94 return (__sprint(iop->fp, &iop->uio));
91 return (__sprint(iop->fp, &iop->uio));
95 }
96 return (0);
92 else
93 return (0);
97}
98
99/*
100 * Choose PADSIZE to trade efficiency vs. size. If larger printf
101 * fields occur frequently, increase PADSIZE and make the initialisers
102 * below longer.
103 */
104#define PADSIZE 16 /* pad chunk size */

--- 4 unchanged lines hidden (view full) ---

109
110/*
111 * Pad with blanks or zeroes. 'with' should point to either the blanks array
112 * or the zeroes array.
113 */
114static inline int
115io_pad(struct io_state *iop, int howmany, const CHAR * __restrict with)
116{
94}
95
96/*
97 * Choose PADSIZE to trade efficiency vs. size. If larger printf
98 * fields occur frequently, increase PADSIZE and make the initialisers
99 * below longer.
100 */
101#define PADSIZE 16 /* pad chunk size */

--- 4 unchanged lines hidden (view full) ---

106
107/*
108 * Pad with blanks or zeroes. 'with' should point to either the blanks array
109 * or the zeroes array.
110 */
111static inline int
112io_pad(struct io_state *iop, int howmany, const CHAR * __restrict with)
113{
114 int n;
117
115
118 while (howmany > PADSIZE) {
119 if (io_print(iop, with, PADSIZE))
116 while (howmany > 0) {
117 n = (howmany >= PADSIZE) ? PADSIZE : howmany;
118 if (io_print(iop, with, n))
120 return (-1);
119 return (-1);
121 howmany -= PADSIZE;
120 howmany -= n;
122 }
121 }
123 if (howmany > 0 && io_print(iop, with, howmany))
124 return (-1);
125 return (0);
126}
127
128/*
129 * Print exactly len characters of the string spanning p to ep, truncating
130 * or padding with 'with' as necessary.
131 */
132static inline int
133io_printandpad(struct io_state *iop, const CHAR *p, const CHAR *ep,
134 int len, const CHAR * __restrict with)
135{
136 int p_len;
137
138 p_len = ep - p;
139 if (p_len > len)
140 p_len = len;
122 return (0);
123}
124
125/*
126 * Print exactly len characters of the string spanning p to ep, truncating
127 * or padding with 'with' as necessary.
128 */
129static inline int
130io_printandpad(struct io_state *iop, const CHAR *p, const CHAR *ep,
131 int len, const CHAR * __restrict with)
132{
133 int p_len;
134
135 p_len = ep - p;
136 if (p_len > len)
137 p_len = len;
141 if (p_len > 0 && io_print(iop, p, p_len))
142 return (-1);
143 return (io_pad(iop, len - (p_len > 0 ? p_len : 0), with));
138 if (p_len > 0) {
139 if (io_print(iop, p, p_len))
140 return (-1);
141 } else {
142 p_len = 0;
143 }
144 return (io_pad(iop, len - p_len, with));
144}
145
146static inline int
147io_flush(struct io_state *iop)
148{
149
145}
146
147static inline int
148io_flush(struct io_state *iop)
149{
150
150 iop->iovp = iop->iov;
151 return (__sprint(iop->fp, &iop->uio));
152}
153
154/*
155 * Convert an unsigned long to ASCII for printf purposes, returning
156 * a pointer to the first character of the string representation.
157 * Octal numbers can be forced to have a leading zero; hex numbers
158 * use the given digits.

--- 188 unchanged lines hidden ---
151 return (__sprint(iop->fp, &iop->uio));
152}
153
154/*
155 * Convert an unsigned long to ASCII for printf purposes, returning
156 * a pointer to the first character of the string representation.
157 * Octal numbers can be forced to have a leading zero; hex numbers
158 * use the given digits.

--- 188 unchanged lines hidden ---