File descriptors and streams and copying thereof.

Robert Seals rds95 at leah.Albany.Edu
Thu Apr 13 00:08:50 AEST 1989


I want to be able to make "stdin" read from someplace besides, well,
standard input in the middle of my program, and then go back to where
it was again. Think "lex" and "yacc"...

So what I did was this:

	FILE *my_file;

	/* sucessfully open "my_file" */
	...
	stdin->fd = my_file->fd;
	if (yyparse()) /* stuff*/ else /* stuff */
	stdin->fd = 0;	/* presume stdin is/was fd 0 */
	...

which seems to work - most of the time. So, is this truly icky style
or what, and what is the right way to do it?
And BTW, if you refer me to "dup" or something like it, could you also
please explain what it's supposed to do...the man pages for it are not
at all clear to me.

muchos,
rob



More information about the Comp.lang.c mailing list