map empty file on ubuntu
mrka124 opened this issue · 2 comments
On windows, I specific file size and it works normally but not on ubuntu. It causes bus error like https://stackoverflow.com/questions/20587935/bus-error-opening-and-mmaping-a-file
When calling mmap.Map()
for an empty file it returns a proper error for me that can be displayed like this:
if err != nil {
panic(err.Error())
}
That means: no bus error is caused
Example output:
panic: invalid argument
This is due to how POSIX specifies mmap() (cf. mmap(3p)):
If len is zero, mmap() shall fail and no mapping shall be established.
And on Linux is thus fails with EINVAL
.
This package could catch this case, i.e. if file size is zero then return an empty slice instead of doing a real mapping.
PS: Newer versions of this package test for zero length but return a custom error message instead of returning an empty slice:
Closing since this is addresses in newer releases.