Source file src/internal/syscall/unix/at.go

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build linux || openbsd || netbsd || dragonfly
     6  
     7  package unix
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  func Unlinkat(dirfd int, path string, flags int) error {
    15  	var p *byte
    16  	p, err := syscall.BytePtrFromString(path)
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	_, _, errno := syscall.Syscall(unlinkatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags))
    22  	if errno != 0 {
    23  		return errno
    24  	}
    25  
    26  	return nil
    27  }
    28  
    29  func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
    30  	var p *byte
    31  	p, err := syscall.BytePtrFromString(path)
    32  	if err != nil {
    33  		return 0, err
    34  	}
    35  
    36  	fd, _, errno := syscall.Syscall6(openatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
    37  	if errno != 0 {
    38  		return 0, errno
    39  	}
    40  
    41  	return int(fd), nil
    42  }
    43  
    44  func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
    45  	var p *byte
    46  	p, err := syscall.BytePtrFromString(path)
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	_, _, errno := syscall.Syscall6(fstatatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
    52  	if errno != 0 {
    53  		return errno
    54  	}
    55  
    56  	return nil
    57  
    58  }
    59  

View as plain text