This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Getting a (FILE *) from a file descriptor


Sorry, this is new to me. Can I try to populate your function calls with
parameters so I know what you mean? The first dup() makes a temporary fd
presumably. Then the fclose results in the original fd being closed. So
the dup2 must be to restore the port's fd which we closed. Thus:

fp = fdopen(origfd)

 .
 . now we use fp to write to the file
 .

tempfd = dup(origfd)
flcose (fp)
dup2(tempfd, origfd)

Is this it?

Actually there are other problems with using a port's underlying fd. What
happens when the scheme code writes to the port whose fd is being written
to directly. It will surely all go horribly wrong. The port's write buffer
pointer will go out of line with the file position.

Perhaps I should change the trace code so it just traces directly to a
newly opened file, rather than to an arbitrary guile fport.

Ian

 On Thu, 24 Jun 1999, Chris Bitmead wrote:

> 
> Seems a shame to waste a fd carelessly. How about
> dup()
> fclose()
> dup2()
> upon file close so that the fd is only wasted for a fraction of a
> second.
> 
> Ken Raeburn wrote:
> > 
> > Ian Grant <I.A.N.Grant@damtp.cam.ac.uk> writes:
> > 
> > > Oops, it's fdopen isn't it? I was even staring at the man page. Sorry.
> > 
> > Well, fdopen is okay, but calling fclose will result in the file
> > descriptor being closed.  A dup and fdopen would probably work more
> > cleanly.  (You are going to make sure the FILE* gets closed, right?)
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]