Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / sup / source / vprintf.c
blob42dee54ef6ef7f95888139ac7a182cc23be757f3
1 /* $NetBSD: vprintf.c,v 1.8 2002/07/10 20:19:48 wiz Exp $ */
3 /*
4 * Copyright (c) 1991 Carnegie Mellon University
5 * All Rights Reserved.
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 **********************************************************************
31 * HISTORY
32 * Revision 2.5 89/09/08 18:15:55 mbj
33 * Use _doprnt() for the Multimax (an "old" architecture).
34 * [89/09/08 mbj]
36 * Revision 2.4 89/08/03 14:40:10 mja
37 * Add vsnprintf() routine.
38 * [89/07/12 mja]
40 * Terminate vsprintf() string with null byte.
41 * [89/04/21 mja]
43 * Change to use new hidden name for _doprnt on MIPS.
44 * [89/04/18 mja]
46 * Revision 2.3 89/06/10 14:13:43 gm0w
47 * Added putc of NULL byte to vsprintf.
48 * [89/06/10 gm0w]
50 * Revision 2.2 88/12/13 13:53:17 gm0w
51 * From Brad White.
52 * [88/12/13 gm0w]
53 ************************************************************
56 #include <stdio.h>
57 #include <stdarg.h>
59 #ifdef _IOSTRG
60 #define STRFLAG (_IOSTRG|_IOWRT)/* no _IOWRT: avoid stdio bug */
61 #else
62 #define STRFLAG (_IOREAD) /* XXX: Assume svr4 stdio */
63 #endif
65 #ifdef DOPRINT_VA
67 * system provides _doprnt_va routine
69 #define _doprnt _doprnt_va
70 #else
72 * system provides _doprnt routine
74 #define _doprnt_va _doprnt
75 #endif
78 #ifdef NEED_VPRINTF
79 int
80 vprintf(fmt, args)
81 char *fmt;
82 va_list args;
84 _doprnt(fmt, args, stdout);
85 return (ferror(stdout) ? EOF : 0);
88 int
89 vfprintf(f, fmt, args)
90 FILE *f;
91 char *fmt;
92 va_list args;
94 _doprnt(fmt, args, f);
95 return (ferror(f) ? EOF : 0);
98 int
99 vsprintf(s, fmt, args)
100 char *s, *fmt;
101 va_list args;
103 FILE fakebuf;
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);
111 return (strlen(s));
113 #endif /* NEED_VPRINTF */
115 #if defined(NEED_VSNPRINTF) || defined(NEED_VPRINTF)
117 vsnprintf(s, n, fmt, args)
118 char *s, *fmt;
119 va_list args;
121 FILE fakebuf;
123 fakebuf._flag = STRFLAG;
124 fakebuf._base = (void *) s;
125 fakebuf._ptr = (void *) s;
126 fakebuf._cnt = n - 1;
127 fakebuf._file = -1;
128 _doprnt(fmt, args, &fakebuf);
129 fakebuf._cnt++;
130 putc('\0', &fakebuf);
131 if (fakebuf._cnt < 0)
132 fakebuf._cnt = 0;
133 return (n - fakebuf._cnt - 1);
135 #endif /* NEED_VPRINTF || NEED_VSNPRINTF */