Source file src/internal/syscall/unix/at_libc.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 aix || solaris
     6  
     7  package unix
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  //go:linkname procFstatat libc_fstatat
    15  //go:linkname procOpenat libc_openat
    16  //go:linkname procUnlinkat libc_unlinkat
    17  
    18  var (
    19  	procFstatat,
    20  	procOpenat,
    21  	procUnlinkat uintptr
    22  )
    23  
    24  func Unlinkat(dirfd int, path string, flags int) error {
    25  	p, err := syscall.BytePtrFromString(path)
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	_, _, errno := syscall6(uintptr(unsafe.Pointer(&procUnlinkat)), 3, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), 0, 0, 0)
    31  	if errno != 0 {
    32  		return errno
    33  	}
    34  
    35  	return nil
    36  }
    37  
    38  func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
    39  	p, err := syscall.BytePtrFromString(path)
    40  	if err != nil {
    41  		return 0, err
    42  	}
    43  
    44  	fd, _, errno := syscall6(uintptr(unsafe.Pointer(&procOpenat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
    45  	if errno != 0 {
    46  		return 0, errno
    47  	}
    48  
    49  	return int(fd), nil
    50  }
    51  
    52  func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
    53  	p, err := syscall.BytePtrFromString(path)
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	_, _, errno := syscall6(uintptr(unsafe.Pointer(&procFstatat)), 4, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
    59  	if errno != 0 {
    60  		return errno
    61  	}
    62  
    63  	return nil
    64  }
    65  

View as plain text