[comp.lang.c] Obscure _doprnt and _flsbuf question

seaotter@athena.mit.edu (the old ssrat) (02/14/91)

I know, I know, users are supposed to use _doprnt() and all, but
given that I am trying to transport some code that DOES, can any
one tell me what _flsbuf() is doing in the code fragment below?

   (taken from doprnt.c, in the uunet bsd-sources archives)

   fp->_cnt = n;
   fp->_ptr = t;
   (void)_flsbuf((u_char)ch,fp);
   n = fp->_cnt;

It LOOKS like a menmonic for "flush buffer" or something similar,
but I'm not certain.  A search through the index of files at uunet
reveals no files with the string "flsbuf" in their names, and a
similar search through the files in /usr/man/cat3 reveals no ref-
erences to flsbuf.

Oh yeah, what I want to do is find a suitable emulation for this
on VMS version 5.2 or so.

Thanks for
your help,
  Mike

PS Happy Valentine's Day!


--
|    Mike Zraly (the old ssrat)    |  "If the King's English was good enough  |
|                                  |   for Jesus, it's good enough for me!"   |
|   mzraly@ldbvax.dnet.lotus.com   |                                          |
|  or c/o seaotter@athena.mit.edu  | -- Texas Governor "Ma" Ferguson, ca 1920 |

richard@aiai.ed.ac.uk (Richard Tobin) (02/14/91)

In article <1991Feb13.175413.3473@athena.mit.edu> seaotter@athena.mit.edu (the old ssrat) writes:
>I know, I know, users are supposed to use _doprnt() and all, but
>given that I am trying to transport some code that DOES, 

If your C provides vfprintf(), you can probably use that instead.

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin@uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin

roarment@immd4.informatik.uni-erlangen.de (Roberto Armenti) (02/15/91)

richard@aiai.ed.ac.uk (Richard Tobin) writes:

>In article <1991Feb13.175413.3473@athena.mit.edu> seaotter@athena.mit.edu (the old ssrat) writes:
>>I know, I know, users are supposed to use _doprnt() and all, but
>>given that I am trying to transport some code that DOES, 

>If your C provides vfprintf(), you can probably use that instead.

Hi. Now I know what _flsbuf() does, i would be interestes in _doprnt too.
I once had a programm that core-dumped in _flsbuf. Any hints ?

	Thanx,
		Roberto

---
*      roarment@immd4.informatik.uni-erlangen.de                       *
*     Roberto Armenti, Loewenichstr. 37, W8520 Erlangen, Germany       *
------------------------------------------------------------------------
      "Beam me up, Scotty. There is no intelligent life on this planet."

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

>>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