It was thus said that the Great Andrey Dobrovolsky once stated:
I've checked the man page for mmap() across a few POSIX systems [1] and
even the POSIX standard [2] and I think your concern is bit overblown. The
map pages always stated that the offset and length have to be a multiple of
a page size. POSIX states:
The system shall always zero-fill any partial page at the end of an
object.
This is also mentioned on the Mac OS-X man page. A random file has a
1/pagesize chance of being exactly a multiple of a pagesize. So in the
common case, the mapping will have a 0-byte at the end. On the rare
occurance of a file having a length of a page size [3], one can always use
mmap() to anonymously map a page and the end of the file mapping.
As for lua_pushexternalstring() requiring a terminating NUL byte, Lua
guarentees that any string will always have a NUL byte, thus easing C
interoperability (a non-NUL terminated string being passed to functions like
printf() or strlen()).
-spc
[1] Linux, Mac OS-X
[2]
https://pubs.opengroup.org/onlinepubs/9799919799/functions/mmap.html
[3] Obtainable via sysconf() (POSIX) or getpagesize()