Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Can ANYONE tell me why this code snippet doesn't work?? Keywords: varargs Message-ID: <14093@mimsy.UUCP> Date: 21 Oct 88 15:15:28 GMT References: <7778@gryphon.CTS.COM> <315@uplog.se> <982@mina.liu.se> <316@uplog.se> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 62 >In article <982@mina.liu.se> mikpe@mina.liu.se (Mikael Pettersson) writes: >>The great advantage in using varargs(3) is PORTABILITY. ... In article <316@uplog.se> thomas@uplog.se (Thomas Hameenaho) writes: >I agree fully with you. However not THAT many systems have v{sf}printf() >(BSD systems doesn't, at least not 4.3) and my response was an attempt >to explain what was wrong with the code. 4.3BSD-tahoe does have v*printf. Here they are. Install in src/lib/libc/stdio. Note that vsprintf has the same bug that sprintf has (it will scribble on a random fd if you print more than 32767 characters). ---------------------------------vsprintf------------------------------ #include #include int vsprintf(str, fmt, ap) char *str, *fmt; va_list ap; { FILE f; int len; f._flag = _IOWRT+_IOSTRG; f._ptr = str; f._cnt = 32767; len = _doprnt(fmt, ap, &f); *f._ptr = 0; return (len); } ---------------------------------vfprintf------------------------------ #include #include int vfprintf(iop, fmt, ap) FILE *iop; char *fmt; va_list ap; { int len; len = _doprnt(fmt, ap, &f); return (ferror(iop) ? EOF : len); } ---------------------------------vprintf------------------------------- #include #include int vprintf(fmt, ap) char *fmt; va_list ap; { int len; len = _doprnt(fmt, ap, stdout); return (ferror(stdout) ? EOF : len); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris