1*0d601874SDavid du Colombier /* 2*0d601874SDavid du Colombier * The authors of this software are Rob Pike and Ken Thompson. 3*0d601874SDavid du Colombier * Copyright (c) 2002 by Lucent Technologies. 4*0d601874SDavid du Colombier * Permission to use, copy, modify, and distribute this software for any 5*0d601874SDavid du Colombier * purpose without fee is hereby granted, provided that this entire notice 6*0d601874SDavid du Colombier * is included in all copies of any software which is or includes a copy 7*0d601874SDavid du Colombier * or modification of this software and in all copies of the supporting 8*0d601874SDavid du Colombier * documentation for such software. 9*0d601874SDavid du Colombier * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10*0d601874SDavid du Colombier * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE 11*0d601874SDavid du Colombier * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12*0d601874SDavid du Colombier * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13*0d601874SDavid du Colombier */ 148ccd4a63SDavid du Colombier #include <u.h> 158ccd4a63SDavid du Colombier #include <libc.h> 16*0d601874SDavid du Colombier #include "fmtdef.h" 178ccd4a63SDavid du Colombier 188ccd4a63SDavid du Colombier int 198ccd4a63SDavid du Colombier sprint(char *buf, char *fmt, ...) 208ccd4a63SDavid du Colombier { 218ccd4a63SDavid du Colombier int n; 22*0d601874SDavid du Colombier uint len; 238ccd4a63SDavid du Colombier va_list args; 248ccd4a63SDavid du Colombier 25*0d601874SDavid du Colombier len = 1<<30; /* big number, but sprint is deprecated anyway */ 26*0d601874SDavid du Colombier /* 27*0d601874SDavid du Colombier * on PowerPC, the stack is near the top of memory, so 28*0d601874SDavid du Colombier * we must be sure not to overflow a 32-bit pointer. 29*0d601874SDavid du Colombier */ 30*0d601874SDavid du Colombier if(buf+len < buf) 31*0d601874SDavid du Colombier len = -(uintptr)buf-1; 32*0d601874SDavid du Colombier 338ccd4a63SDavid du Colombier va_start(args, fmt); 34*0d601874SDavid du Colombier n = vsnprint(buf, len, fmt, args); 358ccd4a63SDavid du Colombier va_end(args); 368ccd4a63SDavid du Colombier return n; 378ccd4a63SDavid du Colombier } 38