2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
30 #define SPRINTF_UNLIMITED -1
31 struct sprintf_state {
38 savechar(char *arg, int c)
40 struct sprintf_state *state = (struct sprintf_state *)arg;
42 if (state->max != SPRINTF_UNLIMITED)
44 if (state->len == state->max)
53 int vsprintf(char *s, const char *fmt, va_list args)
55 struct sprintf_state state;
56 state.max = SPRINTF_UNLIMITED;
60 _doprnt(fmt, args, 0, (void (*)()) savechar, (char *) &state);
66 int vsnprintf(char *s, int size, const char *fmt, va_list args)
68 struct sprintf_state state;
73 _doprnt(fmt, args, 0, (void (*)()) savechar, (char *) &state);
79 int sprintf(char *s, const char *fmt, ...)
85 err = vsprintf(s, fmt, args);
91 int snprintf(char *s, int size, const char *fmt, ...)
97 err = vsnprintf(s, size, fmt, args);