Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!topaz!husc6!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: variable # of args portability? Message-ID: <2332@umcp-cs.UUCP> Date: Thu, 10-Jul-86 15:25:10 EDT Article-I.D.: umcp-cs.2332 Posted: Thu Jul 10 15:25:10 1986 Date-Received: Sat, 12-Jul-86 03:19:23 EDT References: <809@ucbcad.BERKELEY.EDU> <434@dg_rtp.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Distribution: net Organization: University of Maryland, Dept. of Computer Sci. Lines: 56 Summary: v*printf for 4.[123]BSD Vax Unix In article <434@dg_rtp.UUCP> meissner@dg_rtp.UUCP (Michael Meissner) writes: > In the forthcoming ANSI X3J11 standard, as well as System V, are the >functions vprintf, vfprintf, and vsprintf. Instead of taking the argument >list directly, the take the varargs pointer. Thus the calling sequence looks >like (in the ANSI declarative style): > > int vprintf( const char *fmt, va_list varargs_ptr ); > int vfprintf( FILE *stream, const char *fmt, va_list varargs_ptr ); > int vsprintf( char *buffer, const char *fmt, va_list varargs_ptr ); Since none of 4.[123]BSD Vax Unix have these, but they are trivial, here is an (untested) implementation. (Unfortunately, implementing the proper return value is not so trivial, except for vsprintf.) I believe this code will work on a Pyramid as well. #include int vprintf(fmt, args) char *fmt; va_list args; { _doprnt(fmt, args, stdout); return (ferror(stdout) ? EOF : 0); } int vfprintf(f, fmt, args) FILE *f; char *fmt; va_list args; { _doprnt(fmt, args, f); return (ferror(f) ? EOF : 0); } int vsprintf(s, fmt, args) char *s, *fmt; va_list args; { FILE fakebuf; fakebuf._flag = _IOSTRG; /* no _IOWRT: avoid stdio bug */ fakebuf._ptr = s; fakebuf._cnt = 32767; _doprnt(fmt, args, &fakebuf); return (strlen(s)); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu