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


Chris Bitmead <cbitmead@ozemail.com.au> writes:

> Ian Grant wrote:
> > tempfd = dup(origfd)
> > flcose (fp)
> > dup2(tempfd, origfd)
> 
> That's what I had in mind. As for being thread safe, as you mention, if
> you've got threads writing to the fd while using the buffered FILE
> you've got other more important problems than worrying about thread
> safe.

This code has a problem even if only one thread knows about
origfd.  Between fclose and dup2, the number in origfd is free.
If another thread opens a file, it may get that fd.  Then dup2
hits and the other thread is suddenly using the wrong file.

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