Blob


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