[poppler] UniqueFileStream and deleted files

Ihar `Philips` Filipau thephilips at gmail.com
Sun Mar 24 06:03:49 PDT 2013


On 3/24/13, Fabio D'Urso <fabiodurso at hotmail.it> wrote:
>> On 3/23/13, Albert Astals Cid <aacid at kde.org> wrote:
>> > Anyone with a mac to try?
>
> I have an old powerpc-based mac with MacOSX 10.4 and it seems you can delete
>
> open files there too. I'm attaching the script I've used to test it.
>

Deleting an open files is an old *NIX feature. It appeared out of the
fact that file can have many names. See man 2 link. On *NIX, unlink()
doesn't delete the file - it deletes potentially one of its names.
File is actually deleted when there are no more names referencing to
it. On Windows, hard links/etc appeared much much later and it is now
simply historical feature. (The difference is the reason why Linux can
update itself mostly without reboots - but Windows can't.)

>> Just tried. Mac OS X doesn't have procfs.
>
> Btw, I've found an interesting "pread" call in the man pages:
>  ssize_t pread(int fd, void *buf, size_t count, off_t offset)
>
> It is present both in Linux and Mac OS X.
>

pread() (and its sibling pwrite()) are old POSIX calls and are
available literally everywhere.

If you want to use them in the MT context, you would have to maintain
an offset variable per reader object, and update the offset variable
after every read operation (since pread() doesn't update the filedes'
internal offset). And code somewhere to actually close the file, after
all the reader threads have terminated.


More information about the poppler mailing list