1 /* $NetBSD: vprintf.c,v 1.8 2002/07/10 20:19:48 wiz Exp $ */
4 * Copyright (c) 1991 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie the rights
25 * to redistribute these changes.
28 * varargs versions of printf routines
30 **********************************************************************
32 * Revision 2.5 89/09/08 18:15:55 mbj
33 * Use _doprnt() for the Multimax (an "old" architecture).
36 * Revision 2.4 89/08/03 14:40:10 mja
37 * Add vsnprintf() routine.
40 * Terminate vsprintf() string with null byte.
43 * Change to use new hidden name for _doprnt on MIPS.
46 * Revision 2.3 89/06/10 14:13:43 gm0w
47 * Added putc of NULL byte to vsprintf.
50 * Revision 2.2 88/12/13 13:53:17 gm0w
53 ************************************************************
60 #define STRFLAG (_IOSTRG|_IOWRT)/* no _IOWRT: avoid stdio bug */
62 #define STRFLAG (_IOREAD) /* XXX: Assume svr4 stdio */
67 * system provides _doprnt_va routine
69 #define _doprnt _doprnt_va
72 * system provides _doprnt routine
74 #define _doprnt_va _doprnt
84 _doprnt(fmt
, args
, stdout
);
85 return (ferror(stdout
) ? EOF
: 0);
89 vfprintf(f
, fmt
, args
)
94 _doprnt(fmt
, args
, f
);
95 return (ferror(f
) ? EOF
: 0);
99 vsprintf(s
, fmt
, args
)
105 fakebuf
._flag
= STRFLAG
;
106 fakebuf
._base
= (void *) s
;
107 fakebuf
._ptr
= (void *) s
;
108 fakebuf
._cnt
= 32767;
109 _doprnt(fmt
, args
, &fakebuf
);
110 putc('\0', &fakebuf
);
113 #endif /* NEED_VPRINTF */
115 #if defined(NEED_VSNPRINTF) || defined(NEED_VPRINTF)
117 vsnprintf(s
, n
, fmt
, args
)
123 fakebuf
._flag
= STRFLAG
;
124 fakebuf
._base
= (void *) s
;
125 fakebuf
._ptr
= (void *) s
;
126 fakebuf
._cnt
= n
- 1;
128 _doprnt(fmt
, args
, &fakebuf
);
130 putc('\0', &fakebuf
);
131 if (fakebuf
._cnt
< 0)
133 return (n
- fakebuf
._cnt
- 1);
135 #endif /* NEED_VPRINTF || NEED_VSNPRINTF */