Can ANYONE tell me why this code snippet doesn't work??

Chris Torek chris at mimsy.UUCP
Sat Oct 22 01:15:28 AEST 1988


>In article <982 at mina.liu.se> mikpe at mina.liu.se (Mikael Pettersson) writes:
>>The great advantage in using varargs(3) is PORTABILITY. ...

In article <316 at uplog.se> thomas at 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 <stdio.h>
#include <varargs.h>

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 <stdio.h>
#include <varargs.h>

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 <stdio.h>
#include <varargs.h>

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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list