ReactOS 0.4.15-dev-8241-g63935f8
jsprintf.c
Go to the documentation of this file.
1/* @(#)jsprintf.c 1.20 17/08/03 Copyright 1985, 1995-2017 J. Schilling */
2/*
3 * Copyright (c) 1985, 1995-2017 J. Schilling
4 */
5/*
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License, Version 1.0 only
8 * (the "License"). You may not use this file except in compliance
9 * with the License.
10 *
11 * See the file CDDL.Schily.txt in this distribution for details.
12 * A copy of the CDDL is also available via the Internet at
13 * http://www.opensource.org/licenses/cddl1.txt
14 *
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file CDDL.Schily.txt from this distribution.
17 */
18
19#include <schily/mconfig.h>
20#include <schily/stdio.h>
21#include <schily/types.h>
22#include <schily/varargs.h>
23#include <schily/standard.h>
24#include <schily/schily.h>
25
26#ifdef NO_FPRFORMAT
27#undef USE_FPRFORMAT
28#else
29#define USE_FPRFORMAT
30#endif
31
32#ifdef USE_FPRFORMAT
33/*
34 * This is the speed-optimized version that currently only has been tested
35 * on Solaris.
36 * It is based on fprformat() instead of format() and is faster than the
37 * the format() based standard implementation, in case that putc() or
38 * putc_unlocked() is a macro.
39 */
40
41/* VARARGS1 */
42#ifdef PROTOTYPES
43EXPORT int
44js_printf(const char *form, ...)
45#else
46EXPORT int
47js_printf(form, va_alist)
48 char *form;
49 va_dcl
50#endif
51{
53 int ret;
54
55#ifdef PROTOTYPES
57#else
59#endif
60 ret = fprformat(stdout, form, args);
61 va_end(args);
62 return (ret);
63}
64
65/* VARARGS2 */
66#ifdef PROTOTYPES
67EXPORT int
68js_fprintf(FILE *file, const char *form, ...)
69#else
70EXPORT int
71js_fprintf(file, form, va_alist)
72 FILE *file;
73 char *form;
74 va_dcl
75#endif
76{
78 int ret;
79
80#ifdef PROTOTYPES
82#else
84#endif
85 ret = fprformat(file, form, args);
86 va_end(args);
87 return (ret);
88}
89
90#else /* !USE_FPRFORMAT */
91/*
92 * This is the portable standard implementation that works anywhere.
93 */
94
95#define BFSIZ 256
96
97typedef struct {
98 short cnt;
99 char *ptr;
100 char buf[BFSIZ];
101 int count;
102 FILE *f;
103} *BUF, _BUF;
104
105LOCAL void _bflush __PR((BUF));
106LOCAL void _bput __PR((char, void *));
107EXPORT int js_fprintf __PR((FILE *, const char *, ...));
108EXPORT int js_printf __PR((const char *, ...));
109
110LOCAL void
111_bflush(bp)
112 register BUF bp;
113{
114 bp->count += bp->ptr - bp->buf;
115 if (filewrite(bp->f, bp->buf, bp->ptr - bp->buf) < 0)
116 bp->count = EOF;
117 bp->ptr = bp->buf;
118 bp->cnt = BFSIZ;
119}
120
121#ifdef PROTOTYPES
122LOCAL void
123_bput(char c, void *l)
124#else
125LOCAL void
126_bput(c, l)
127 char c;
128 void *l;
129#endif
130{
131 register BUF bp = (BUF)l;
132
133 *bp->ptr++ = c;
134 if (--bp->cnt <= 0)
135 _bflush(bp);
136}
137
138/* VARARGS1 */
139#ifdef PROTOTYPES
140EXPORT int
141js_printf(const char *form, ...)
142#else
143EXPORT int
144js_printf(form, va_alist)
145 char *form;
146 va_dcl
147#endif
148{
150 _BUF bb;
151
152 bb.ptr = bb.buf;
153 bb.cnt = BFSIZ;
154 bb.count = 0;
155 bb.f = stdout;
156#ifdef PROTOTYPES
158#else
159 va_start(args);
160#endif
161 format(_bput, &bb, form, args);
162 va_end(args);
163 if (bb.cnt < BFSIZ)
164 _bflush(&bb);
165 return (bb.count);
166}
167
168/* VARARGS2 */
169#ifdef PROTOTYPES
170EXPORT int
171js_fprintf(FILE *file, const char *form, ...)
172#else
173EXPORT int
174js_fprintf(file, form, va_alist)
175 FILE *file;
176 char *form;
177 va_dcl
178#endif
179{
181 _BUF bb;
182
183 bb.ptr = bb.buf;
184 bb.cnt = BFSIZ;
185 bb.count = 0;
186 bb.f = file;
187#ifdef PROTOTYPES
189#else
190 va_start(args);
191#endif
192 format(_bput, &bb, form, args);
193 va_end(args);
194 if (bb.cnt < BFSIZ)
195 _bflush(&bb);
196 return (bb.count);
197}
198#endif
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
r l[0]
Definition: byte_order.h:168
EXPORT ssize_t filewrite(FILE *f, void *vbuf, size_t len)
Definition: filewrite.c:71
int form
Definition: main.c:89
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const GLubyte * c
Definition: glext.h:8905
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define stdout
Definition: stdio.h:99
#define EOF
Definition: stdio.h:24
#define LOCAL(type)
Definition: jmorecfg.h:289
EXPORT int js_printf(char *form, va_alist)
Definition: jsprintf.c:47
EXPORT int js_fprintf(FILE *file, char *form, va_alist)
Definition: jsprintf.c:71
struct BUF _BUF
#define f
Definition: ke_i.h:83
#define c
Definition: ke_i.h:80
static PVOID ptr
Definition: dispmode.c:27
#define __PR(a)
Definition: prototyp.h:106
#define args
Definition: format.c:66
#define BUF
Definition: skelserver.c:12
Definition: jssnprintf.c:29
int count
Definition: jssnprintf.c:31
char * ptr
Definition: jssnprintf.c:30
Definition: match.c:390
Definition: fci.c:127
int ret