gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/internal/syscall/unix/at.go (about) 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 // +build linux openbsd netbsd dragonfly 7 8 package unix 9 10 import ( 11 "syscall" 12 "unsafe" 13 ) 14 15 func Unlinkat(dirfd int, path string, flags int) error { 16 var p *byte 17 p, err := syscall.BytePtrFromString(path) 18 if err != nil { 19 return err 20 } 21 22 _, _, errno := syscall.Syscall(unlinkatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags)) 23 if errno != 0 { 24 return errno 25 } 26 27 return nil 28 } 29 30 func Openat(dirfd int, path string, flags int, perm uint32) (int, error) { 31 var p *byte 32 p, err := syscall.BytePtrFromString(path) 33 if err != nil { 34 return 0, err 35 } 36 37 fd, _, errno := syscall.Syscall6(openatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0) 38 if errno != 0 { 39 return 0, errno 40 } 41 42 return int(fd), nil 43 } 44 45 func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error { 46 var p *byte 47 p, err := syscall.BytePtrFromString(path) 48 if err != nil { 49 return err 50 } 51 52 _, _, errno := syscall.Syscall6(fstatatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0) 53 if errno != 0 { 54 return errno 55 } 56 57 return nil 58 59 }