[poppler] UniqueFileStream and deleted files
Albert Astals Cid
aacid at kde.org
Sat Mar 23 12:08:54 PDT 2013
El Dissabte, 23 de març de 2013, a les 20:01:58, Thomas Freitag va escriure:
> 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.
Exactly, it is the documented behaviour
"They refer to the same open file description and thus share file offset"
> 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 :-(
No. We either write the file back to a temporary location as i suggested in my
initial mail, or use the only fd with locking. I think i'm favoring the second
use case since writing the file back might not even work if we run out of free
> > 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
> > .
> poppler mailing list
> poppler at lists.freedesktop.org
More information about the poppler