github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/pcsutil/prealloc/prealloc.go (about)

     1  //+build !windows,!plan9
     2  
     3  // Package prealloc 初始化分配文件包
     4  package prealloc
     5  
     6  import (
     7  	"syscall"
     8  )
     9  
    10  // PreAlloc 预分配文件空间
    11  func PreAlloc(fd uintptr, length int64) error {
    12  	err := syscall.Ftruncate(int(fd), length)
    13  	if err != nil {
    14  		return &PreAllocError{
    15  			ProcName: "Ftruncate",
    16  			Err:      err,
    17  		}
    18  	}
    19  	return nil
    20  }