[net.unix] an inquiry about 4.2 stdio.h

edward@ukma.UUCP (Edward C. Bennett) (06/24/85)

	In stdio.h on 4.2BSD, this line appears

#define	_IOSTRG	0100

	This isn't in (at least I havn't been able to find it) in either
2.9BSD or sysV.

	Can someone please tell me what effect _IOSTRG has so that I
can (attempt) to emulate it?


-- 
edward
		{decvax,ihnp4,mhuxt,seismo}! -+-> cbosgd! --> ukma!edward
    ()		{clyde,osu-eddie,ulysses}! ---|
    |
    |--		"Well, what's on the television then?"
   /|---	"Looks like a penguin."
  |     \  _
   \___/ \=	Support barrier free design

guy@sun.uucp (Guy Harris) (06/26/85)

> 	In stdio.h on 4.2BSD, this line appears
> 
> #define	_IOSTRG	0100
> 
> 	This isn't in (at least I havn't been able to find it) in either
> 2.9BSD or sysV.
> 
> 	Can someone please tell me what effect _IOSTRG has so that I
> can (attempt) to emulate it?

It tells the standard I/O library that what it thinks is a stream is really
a fake stream set up temporarily by "sprintf" or "sscanf".  The fake
stream's "buffer" is the string being scanned or printed into.  "IOSTRG"
tells it not to do something dumb with that stream, like trying to do real
live I/O into or from the buffer.

There's no need to simulate it.  The only semi-valid reason why *anybody*
should be using that flag is if they're duplicating the code in "sprintf" or
"sscanf".  Your best bet is to rewrite the code so it doesn't use
undocumented internal interfaces to standard I/O which are 1) not guaranteed
to be the same in all implementations of the standard I/O library and 2) not
even guaranteed to stay the same in different releases of the same
implementation.  Barring that, if you really must sneak in through the back
door you should rip off the code from the 2.9BSD/SysV standard I/O library
and use it (if you don't have the source, do some disassembly; if you can't
do that, reconsider whether you shouldn't just rewrite it not to use the
back door).

	Guy Harris

chris@umcp-cs.UUCP (Chris Torek) (06/28/85)

> "IOSTRG" tells [stdio] not to do something dumb with that stream,
> like trying to do real live I/O into or from the buffer.

I probably shouldn't be putting more verbiage onto the net, but I
can't let this go by without comment.

One would *think* that this is what _IOSTRG does.  In fact _IOSTRG
has no effect whatsoever.  If you run the following under 4.1 or 4.2BSD,
it will write to file descriptor 0:

	#include <stdio.h>

	main() {
		struct _iobuf io;
		char place[3];

		io._cnt = 3;
		io._base = io._ptr = place;
		io._flag = _IOWRT|_IOSTRG;
		_doprnt("testing...", 0, &io);
		exit(0);
	}

(The io._base initialization is just to make it something other
than NULL, since it's in zero filled stack space.)

To make it work properly, you have to (get this) take away _IOWRT.
Properly, by the way, means it should put ``tes'' into place[]
and then return a failure indication.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (06/28/85)

> #define	_IOSTRG	0100

That was a kludge to support sprintf()/sscanf().
UNIX System V uses a different kludge for this purpose.