_IOSTRG in stdio.h

der Mouse mouse at mcgill-vision.UUCP
Tue Nov 15 20:12:36 AEST 1988


In article <14413 at mimsy.UUCP>, chris at mimsy.UUCP (Chris Torek) writes:
> In article <1004 at cps3xx.UUCP> usenet at cps3xx.UUCP (Usenet file owner) writes:
>> Could someone tell me what the _IOSTRG parameter in stdio.h on BSD
>> controls?
> Absolutely nothing.  It is never tested.  You can expect it to vanish
> in the future.

[Reality check time: I'm about to disagree with Chris.]

>From flsbuf.c:
	fclose(iop)
		register FILE *iop;
	{
....
		if (iop->_flag&(_IOREAD|_IOWRT|_IORW) && (iop->_flag&_IOSTRG)==0) {

>From filbuf.c:
	_filbuf(iop)
	register FILE *iop;
	{
....
		if (iop->_flag&(_IOSTRG|_IOEOF))

(And yes, Chris, this is the distribution stdio, not my stdio.)

To answer what the original poster probably wanted to know, _IOSTRG
indicates that the stream is a fake stream for I/O to a string: sprintf
or sscanf.  As for what it actually *controls*, Chris is almost
correct; I think _doprnt doesn't check this flag at all [VAX version],
and (bug alert!) neither does _flsbuf.  If you sprintf more than 32K,
sprintf will make mistakes.  Initially, the mistakes are (relatively)
benign (the sprintffed output past 32K gets stuffed in malloc()ed
memory which is then lost), but if you push it to 40K, it will start
flushing stuff to a random file descriptor ("random" = "stack trash"),
which in my tests happened to be 0, the standard input.  Examination of
the code indicates that potential exists for it to drop core if it gets
the wrong stack trash.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list