| 1234567891011121314151617181920212223242526272829 |
- //go:build !linux
- // +build !linux
- /*
- * SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
- * SPDX-License-Identifier: Apache-2.0
- */
- package z
- import "fmt"
- // Truncate would truncate the mmapped file to the given size. On Linux, we truncate
- // the underlying file and then call mremap, but on other systems, we unmap first,
- // then truncate, then re-map.
- func (m *MmapFile) Truncate(maxSz int64) error {
- if err := m.Sync(); err != nil {
- return fmt.Errorf("while sync file: %s, error: %v\n", m.Fd.Name(), err)
- }
- if err := Munmap(m.Data); err != nil {
- return fmt.Errorf("while munmap file: %s, error: %v\n", m.Fd.Name(), err)
- }
- if err := m.Fd.Truncate(maxSz); err != nil {
- return fmt.Errorf("while truncate file: %s, error: %v\n", m.Fd.Name(), err)
- }
- var err error
- m.Data, err = Mmap(m.Fd, true, maxSz) // Mmap up to max size.
- return err
- }
|