[comp.archives] [comp.lang.c] Re: Obscure _doprnt and _flsbuf question

torek@elf.ee.lbl.gov (Chris Torek) (02/16/91)

Archive-name: c/library/bsd-stdio/1991-02-16
Archive: mimsy.umd.edu:/pub/stdio.tar.Z [128.8.128.8]
Original-posting-by: torek@elf.ee.lbl.gov (Chris Torek)
Original-subject: Re: Obscure _doprnt and _flsbuf question
Reposted-by: emv@ox.com (Edward Vielmetti)

>>In article <1991Feb13.175413.3473@athena.mit.edu> seaotter@athena.mit.edu
(the old ssrat) asks what _flsbuf does.

In article <1991Feb15.114733.27855@informatik.uni-erlangen.de>
roarment@immd4.informatik.uni-erlangen.de (Roberto Armenti) writes:
>... I would be interested in _doprnt too.

Neither routine exists at all.

Or rather, neither routine exists at all in the C library on the current
4BSD development systems.

Both of these routines were (and still are on other systems) internal
functions implementing parts of stdio.

_doprnt implemented vfprintf.  printf, fprintf, vprintf, and vfprintf
are, semantically at least, just front-ends to vfprintf; sprintf and
vsprintf use the same internals in these implementations---in some
cases, with interesting bugs as a side effect (try printing 32770 bytes
to a string).

_flsbuf implemented part of putc(): namely, the part that puts a character
when the current buffer is full.  (This is an oversimplification.)

You must not use either routine, since they do not exist.

>richard@aiai.ed.ac.uk (Richard Tobin) writes:
>>If your C provides vfprintf(), you can probably use that instead.

You may have to restructure the surrounding code.  Do so.

If you do not have vfprintf, the best fix is to add it.  The following
may work:

	int vfprintf(f, fmt, ap) FILE *f; char *fmt; va_list ap; {
		return _doprnt(fmt, ap, f);
	}

If you need vsprintf (and do not already have it), the following may work:

	int vsprintf(buf, fmt, ap) char *buf, *fmt; va_list ap; {
		int ret;
		FILE f;

		f._base = f._ptr = buf;
		f._flag = _IOWRT | _IOSTRG;
		f._cnt = 32767;	/* interesting bug here: f._file is junk */
		ret = _doprnt(fmt, ap, &f);
		*f._ptr = 0;
		return ret;
	}

A complete (if slightly buggy) Unix stdio implementation, sans manuals,
is available for anonymous FTP from host mimsy.umd.edu as a compressed tar
file in pub/stdio.tar.Z.  The same thing, with bugs fixed and man pages,
will be on the next BSD tape.
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov