[net.micro.atari16] Fforce

pm@cwruecmp.UUCP (Prabhaker Mateti) (10/21/86)

/*
In a program I am writing, I need to redirect input/output.  E.g., to
redirect input from a file, I do  Fforce(0, fd), but then I can't close
the fd and reuse that handle.  The following code demonstrates this.
Any body has a clue as to what is wrong here??
*/

#include <osbind.h>

main()
{
	int	fi, ff, fc, i;

	for (i=0; i < 81; i++)
	{	fi = Fopen  ("in", 0);
		ff = Fforce(0, fi);
		fc = Fclose(fi);
		printf("fi ff fc %d %d %d \n", fi, ff, fc);
	}
}

dyer@atari.UUcp (Landon Dyer) (11/01/86)

In article <1639@cwruecmp.UUCP>, pm@cwruecmp.UUCP (Prabhaker Mateti) writes:
> /*
> In a program I am writing, I need to redirect input/output.  E.g., to
> redirect input from a file, I do  Fforce(0, fd), but then I can't close
> the fd and reuse that handle.  The following code demonstrates this.
> Any body has a clue as to what is wrong here??
> */
> 
> #include <osbind.h>
> 
> main()
> {
> 	int	fi, ff, fc, i;
> 
> 	for (i=0; i < 81; i++)
> 	{	fi = Fopen  ("in", 0);
> 		ff = Fforce(0, fi);
> 		fc = Fclose(fi);
> 		printf("fi ff fc %d %d %d \n", fi, ff, fc);
> 	}
> }

The problem here is the Fclose(fi) --- you can't close a handle, even
after an Fforce, because handles in GEMDOS are shared between ALL
processes.  [In theory, you could open a file, do a Pexec(), and have
the child process do I/O on the handle that the parent opened.  In
practice, this is a bad practice....]

Negative handles correspond (kind of) to BIOS devices, -1 is CON:, -2
is AUX:, and so on.  Handles from 0 to 5 are "standard" handles, and
are inherited by the child on a Pexec().  Handles 6 and up always
refer to files.  Standard handles are a kind of indirection; they
"point" to a character device (handle < 0) or a file handle (> 5).

-- 

-Landon Dyer, Atari Corp.		        {sun,lll-lcc,imagen}!atari!dyer

/-----------------------------------------------\
| The views represented here do not necessarily | "If Business is War, then
| reflect those of Atari Corp., or even my own. |  I'm a Prisoner of Business!"
\-----------------------------------------------/