Blame


1 91c13e54 2004-02-29 devnull /*
2 91c13e54 2004-02-29 devnull * The authors of this software are Rob Pike and Ken Thompson.
3 91c13e54 2004-02-29 devnull * Copyright (c) 2002 by Lucent Technologies.
4 91c13e54 2004-02-29 devnull * Permission to use, copy, modify, and distribute this software for any
5 91c13e54 2004-02-29 devnull * purpose without fee is hereby granted, provided that this entire notice
6 91c13e54 2004-02-29 devnull * is included in all copies of any software which is or includes a copy
7 91c13e54 2004-02-29 devnull * or modification of this software and in all copies of the supporting
8 91c13e54 2004-02-29 devnull * documentation for such software.
9 91c13e54 2004-02-29 devnull * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10 c90dd38f 2004-12-29 devnull * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE
11 c90dd38f 2004-12-29 devnull * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12 91c13e54 2004-02-29 devnull * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
13 91c13e54 2004-02-29 devnull */
14 91c13e54 2004-02-29 devnull #include <stdarg.h>
15 b4c842f1 2004-09-17 devnull #include <fmt.h>
16 e5aa96ac 2004-12-26 devnull #include "plan9.h"
17 e5aa96ac 2004-12-26 devnull #include "fmt.h"
18 b4c842f1 2004-09-17 devnull #include "fmtdef.h"
19 91c13e54 2004-02-29 devnull
20 91c13e54 2004-02-29 devnull int
21 91c13e54 2004-02-29 devnull sprint(char *buf, char *fmt, ...)
22 91c13e54 2004-02-29 devnull {
23 91c13e54 2004-02-29 devnull int n;
24 984e3531 2004-08-22 devnull uint len;
25 91c13e54 2004-02-29 devnull va_list args;
26 91c13e54 2004-02-29 devnull
27 984e3531 2004-08-22 devnull len = 1<<30; /* big number, but sprint is deprecated anyway */
28 984e3531 2004-08-22 devnull /*
29 984e3531 2004-08-22 devnull * on PowerPC, the stack is near the top of memory, so
30 984e3531 2004-08-22 devnull * we must be sure not to overflow a 32-bit pointer.
31 984e3531 2004-08-22 devnull */
32 984e3531 2004-08-22 devnull if(buf+len < buf)
33 984e3531 2004-08-22 devnull len = -(uint)buf-1;
34 984e3531 2004-08-22 devnull
35 91c13e54 2004-02-29 devnull va_start(args, fmt);
36 984e3531 2004-08-22 devnull n = vsnprint(buf, len, fmt, args);
37 91c13e54 2004-02-29 devnull va_end(args);
38 91c13e54 2004-02-29 devnull return n;
39 91c13e54 2004-02-29 devnull }