mirror of
https://github.com/nikdoof/vsphere-influxdb-go.git
synced 2025-12-20 14:09:21 +00:00
add vendoring with go dep
This commit is contained in:
43
vendor/github.com/influxdata/influxdb/pkg/mmap/mmap_unix.go
generated
vendored
Normal file
43
vendor/github.com/influxdata/influxdb/pkg/mmap/mmap_unix.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package mmap provides a way to memory-map a file.
|
||||
package mmap
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// Map memory-maps a file.
|
||||
func Map(path string) ([]byte, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if fi.Size() == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// Unmap closes the memory-map.
|
||||
func Unmap(data []byte) error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
return syscall.Munmap(data)
|
||||
}
|
||||
Reference in New Issue
Block a user