/*
 * SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
 * SPDX-License-Identifier: Apache-2.0
 */

package z

import (
	
)

// 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 ( *MmapFile) ( int64) error {
	if  := .Sync();  != nil {
		return fmt.Errorf("while sync file: %s, error: %v\n", .Fd.Name(), )
	}
	if  := .Fd.Truncate();  != nil {
		return fmt.Errorf("while truncate file: %s, error: %v\n", .Fd.Name(), )
	}

	var  error
	.Data,  = mremap(.Data, int()) // Mmap up to max size.
	return 
}