Assessing files through file descriptors

Gert Veldhuijzen van Zanten veldhvz@ipo.tue.nl
Thu, 22 Apr 1999 13:45:31 +0200


Zuurbier, E. - AMSXE wrote:
> 
> > What I would need is a function
> >
> >       fdopen :: Int -> (Bool,!*File)
> >
> I guess that this would conflict with the whole idea of uniqueness and the
> single threaded use of the file that uniqueness is trying to guarantee.
> 
> If the file is already open, as you say, then there may be one reference to
> it, somewhere.

A valid point. However, my problem is that the file is opened by another 
module, and thus that one reference is not available within Clean. In
order
to get that reference into Clean, we need to do some kind of hack.

> If you then use fdopen somewhere else to create a fresh reference to the
> same file,
> you have two references! Uniqueness would and should not allow that.

Agree! So maybe we can add a Files (or World) argument as in my second 
suggestion

        fdopen :: Int Int !*Files -> (Bool,!*File,*Files)

Then accessing the external reference to the file could pervent any
other
reference from being opened again. Thus in

	# (ok,f1,files) = fdopen 125 FReadText files
        | not ok = abort "Cannot open file 125"
	# (ok,f2,files) = fdopen 125 FReadText files

the second call would always fail.


-- 
Gert Veldhuijzen van Zanten      P.O. Box 513, NL-5600 MB  Eindhoven
 ____________________________    +31 40 2475260, fax: +31 40 2431930
| IPO, Center for Research   |                    veldhvz@ipo.tue.nl
|_on User-System Interaction_|  http://www.tue.nl/ipo/people/veldhvz