Obscure _doprnt and _flsbuf question
Chris Torek
torek at elf.ee.lbl.gov
Sat Feb 16 13:50:11 AEST 1991
>>In article <1991Feb13.175413.3473 at athena.mit.edu> seaotter at athena.mit.edu
(the old ssrat) asks what _flsbuf does.
In article <1991Feb15.114733.27855 at informatik.uni-erlangen.de>
roarment at 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 at 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 at ee.lbl.gov
More information about the Comp.lang.c
mailing list