[poppler] UniqueFileStream and deleted files

Albert Astals Cid aacid at kde.org
Sat Mar 23 12:41:23 PDT 2013


El Dissabte, 23 de març de 2013, a les 20:31:52, Ihar `Philips` Filipau va 
escriure:
> On 3/23/13, Albert Astals Cid <aacid at kde.org> wrote:
> > 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"
> 
> Ooops. Missed that bit completely. My understanding of *nix internals
> (slightly) shaked. :(
> 
> I have further googled it up - and found only this procfs solution:

Your google skills are better than mine :D

> 
> sprintf( new_name, "/proc/%d/fd/%d", getpid(), fileno(f) );
> FILE *new_file = fopen( new_name, "r" );
> 
> Works on Linux, Solaris and AIX (the only OSs I know with the procfs;
> HP-UX doesn't have procfs) - but I gather that is little consolation.

Well, it's probably enough, what other OSs are you thinking about?

Windows? You can't delete open files on Windows so it should work.

Maybe MacOs will fail too?

Anyone with a mac to try?

Cheers,
  Albert

> 
> FYI. :(
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler


More information about the poppler mailing list