[poppler] UniqueFileStream and deleted files

Ihar `Philips` Filipau thephilips at gmail.com
Sat Mar 23 12:31:52 PDT 2013


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:

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.

FYI. :(


More information about the poppler mailing list