On 3/23/13, Albert Astals Cid <[email protected]> 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 <[email protected]> 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. :( _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
