mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 12:59:04 +00:00
add os.Truncate(name, size) (see #4209)
See https://pkg.go.dev/os#Truncate
This commit is contained in:
committed by
Ron Evans
parent
2e76cd3687
commit
d6e73b4c68
+14
-8
@@ -55,6 +55,19 @@ func NewFile(fd uintptr, name string) *File {
|
|||||||
return &File{&file{handle: unixFileHandle(fd), name: name}}
|
return &File{&file{handle: unixFileHandle(fd), name: name}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Truncate changes the size of the named file.
|
||||||
|
// If the file is a symbolic link, it changes the size of the link's target.
|
||||||
|
// If there is an error, it will be of type *PathError.
|
||||||
|
func Truncate(name string, size int64) error {
|
||||||
|
e := ignoringEINTR(func() error {
|
||||||
|
return syscall.Truncate(name, size)
|
||||||
|
})
|
||||||
|
if e != nil {
|
||||||
|
return &PathError{Op: "truncate", Path: name, Err: e}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func Pipe() (r *File, w *File, err error) {
|
func Pipe() (r *File, w *File, err error) {
|
||||||
var p [2]int
|
var p [2]int
|
||||||
err = handleSyscallError(syscall.Pipe2(p[:], syscall.O_CLOEXEC))
|
err = handleSyscallError(syscall.Pipe2(p[:], syscall.O_CLOEXEC))
|
||||||
@@ -134,14 +147,7 @@ func (f *File) Truncate(size int64) (err error) {
|
|||||||
return ErrClosed
|
return ErrClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
e := ignoringEINTR(func() error {
|
return Truncate(f.name, size)
|
||||||
return syscall.Truncate(f.name, size)
|
|
||||||
})
|
|
||||||
|
|
||||||
if e != nil {
|
|
||||||
return &PathError{Op: "truncate", Path: f.name, Err: e}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
|
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
|
||||||
|
|||||||
+10
-5
@@ -63,6 +63,12 @@ func (f *unixFileHandle) Truncate(size int64) error {
|
|||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Truncate changes the size of the named file.
|
||||||
|
// If the file is a symbolic link, it changes the size of the link's target.
|
||||||
|
func Truncate(name string, size int64) error {
|
||||||
|
return &PathError{Op: "truncate", Path: name, Err: ErrNotImplemented}
|
||||||
|
}
|
||||||
|
|
||||||
func tempDir() string {
|
func tempDir() string {
|
||||||
n := uint32(syscall.MAX_PATH)
|
n := uint32(syscall.MAX_PATH)
|
||||||
for {
|
for {
|
||||||
@@ -110,14 +116,13 @@ func (f unixFileHandle) Sync() error {
|
|||||||
return ErrNotImplemented
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Truncate changes the size of the named file.
|
||||||
|
// If the file is a symbolic link, it changes the size of the link's target.
|
||||||
func (f *File) Truncate(size int64) error {
|
func (f *File) Truncate(size int64) error {
|
||||||
var err error
|
|
||||||
if f.handle == nil {
|
if f.handle == nil {
|
||||||
err = ErrClosed
|
return &PathError{Op: "truncate", Path: f.name, Err: ErrClosed}
|
||||||
} else {
|
|
||||||
err = ErrNotImplemented
|
|
||||||
}
|
}
|
||||||
return &PathError{Op: "truncate", Path: f.name, Err: err}
|
return Truncate(f.name, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
|
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
|
||||||
|
|||||||
Reference in New Issue
Block a user