variable # of args portability?

Chris Torek chris at umcp-cs.UUCP
Fri Jul 11 05:25:10 AEST 1986


In article <434 at dg_rtp.UUCP> meissner at 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 <stdio.h>

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 at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list