[poppler] UniqueFileStream and deleted files

Thomas Freitag Thomas.Freitag at kabelmail.de
Sat Mar 23 12:01:58 PDT 2013

Am 23.03.2013 18:59, schrieb Ihar `Philips` Filipau:
> On 3/23/13, Ihar `Philips` Filipau <thephilips at gmail.com> wrote:
>>> (i tried to find a way to duplicate a FILE* but failed)
>> How did you duplicate FILE*?
>> How did the `fdopen( fileno(oldfile), mode )` failed?
> Nope. This is the right way:
> int new_fd = dup( fileno(oldfile) );
> FILE *new_file = fdopen( new_fd, mode );
Duplicating the FILE pointer in that way is not a solution: I tried it 
that way when I began to implement thread safe feature: At least under 
Ubuntu and gcc the duplicated file pointer uses the same underlying 
buffer, and that corrupts the thread safe feature. That's why I used the 
fileName to create a complete new file pointer.
Of course we can do it in that way if we detect that the file is deleted 
(and only then!), but a program which use threads to render different 
pages the same time will then render garbage :-(

> It is OK to use *NIX function here - the dup() - since deleting open
> file can happen only on the *NIX-like OS, Mac OS X included. Windows
> doesn't allow that. Correct me if I'm wrong. Tested on Linux, HP-UX
> and Solaris for the safety sake: the fclose() would close the dup()ed
> file descriptor.
> Though I'm not sure how to integrate that with the rest of the portable code. :)
> FYI.
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler
> .

More information about the poppler mailing list