-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathmmap_unix.go
39 lines (31 loc) · 869 Bytes
/
mmap_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//go:build !windows && !appengine && !plan9 && !js && !wasip1 && !wasi
// +build !windows,!appengine,!plan9,!js,!wasip1,!wasi
package maxminddb
import (
"errors"
"os"
"golang.org/x/sys/unix"
)
type mmapENODEVError struct{}
func (mmapENODEVError) Error() string {
return "mmap: the underlying filesystem of the specified file does not support memory mapping"
}
func (mmapENODEVError) Is(target error) bool {
return target == errors.ErrUnsupported
}
func mmap(fd, length int) (data []byte, err error) {
data, err = unix.Mmap(fd, 0, length, unix.PROT_READ, unix.MAP_SHARED)
if err != nil {
if err == unix.ENODEV {
return nil, mmapENODEVError{}
}
return nil, os.NewSyscallError("mmap", err)
}
return data, nil
}
func munmap(b []byte) (err error) {
if err = unix.Munmap(b); err != nil {
return os.NewSyscallError("munmap", err)
}
return nil
}