Blame


1 85231fd8 2006-05-21 devnull /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
2 91c13e54 2004-02-29 devnull #include <stdarg.h>
3 b4c842f1 2004-09-17 devnull #include <fmt.h>
4 e5aa96ac 2004-12-26 devnull #include "plan9.h"
5 e5aa96ac 2004-12-26 devnull #include "fmt.h"
6 b4c842f1 2004-09-17 devnull #include "fmtdef.h"
7 91c13e54 2004-02-29 devnull
8 91c13e54 2004-02-29 devnull int
9 91c13e54 2004-02-29 devnull sprint(char *buf, char *fmt, ...)
10 91c13e54 2004-02-29 devnull {
11 91c13e54 2004-02-29 devnull int n;
12 984e3531 2004-08-22 devnull uint len;
13 91c13e54 2004-02-29 devnull va_list args;
14 91c13e54 2004-02-29 devnull
15 984e3531 2004-08-22 devnull len = 1<<30; /* big number, but sprint is deprecated anyway */
16 984e3531 2004-08-22 devnull /*
17 984e3531 2004-08-22 devnull * on PowerPC, the stack is near the top of memory, so
18 984e3531 2004-08-22 devnull * we must be sure not to overflow a 32-bit pointer.
19 34167aa6 2008-03-04 rsc *
20 34167aa6 2008-03-04 rsc * careful! gcc-4.2 assumes buf+len < buf can never be true and
21 34167aa6 2008-03-04 rsc * optimizes the test away. casting to uintptr works around this bug.
22 984e3531 2004-08-22 devnull */
23 34167aa6 2008-03-04 rsc if((uintptr)buf+len < (uintptr)buf)
24 3d484b0d 2005-12-29 devnull len = -(uintptr)buf-1;
25 984e3531 2004-08-22 devnull
26 91c13e54 2004-02-29 devnull va_start(args, fmt);
27 984e3531 2004-08-22 devnull n = vsnprint(buf, len, fmt, args);
28 91c13e54 2004-02-29 devnull va_end(args);
29 91c13e54 2004-02-29 devnull return n;
30 91c13e54 2004-02-29 devnull }