Subject: | mmap of zero length |
Date: | Tue, 24 Nov 2009 08:14:44 +1100 |
To: | bug-File-Map [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
When doing an mmap of length==0 there's some unhappy different behaviour
on different systems. On past linux kernel it worked, but now fails,
which may be in accordance with POSIX. On freebsd there's a bizarre
thing where the mmap succeeds, but the munmap then fails (which might be
due to change soon).
It'd be good if File::Map brought some uniformity to that. When
mmapping a zero length file or a zero length segment I'd like to see an
empty perl string, without having to worry what the system does or
doesn't normally think of size zero. The pin() and advise() operations
could be noops (which might means keeping the magic on the variable, but
recognising zero length as do-nothing).
I struck this when mmapping files which could potentially be empty.
Although it's not hard to test for an empty file it's a bit tedious and
to avoid a race condition you have to do it after opening the file, and
then have to pass the detected size to map_handle() in case the size
changes just at that moment ...