X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/cmd/vendor/golang.org/x/sys/unix
opt
/
golang
/
1.22.0
/
src
/
cmd
/
vendor
/
golang.org
/
x
/
sys
/
unix
/
📁
..
📄
.gitignore
(16 B)
📄
README.md
(8.48 KB)
📄
affinity_linux.go
(1.88 KB)
📄
aliases.go
(396 B)
📄
asm_aix_ppc64.s
(407 B)
📄
asm_bsd_386.s
(696 B)
📄
asm_bsd_amd64.s
(722 B)
📄
asm_bsd_arm.s
(686 B)
📄
asm_bsd_arm64.s
(709 B)
📄
asm_bsd_ppc64.s
(716 B)
📄
asm_bsd_riscv64.s
(711 B)
📄
asm_linux_386.s
(1.44 KB)
📄
asm_linux_amd64.s
(1.18 KB)
📄
asm_linux_arm.s
(1.11 KB)
📄
asm_linux_arm64.s
(1.08 KB)
📄
asm_linux_loong64.s
(1.16 KB)
📄
asm_linux_mips64x.s
(1.14 KB)
📄
asm_linux_mipsx.s
(1.14 KB)
📄
asm_linux_ppc64x.s
(909 B)
📄
asm_linux_riscv64.s
(1.02 KB)
📄
asm_linux_s390x.s
(1.12 KB)
📄
asm_openbsd_mips64.s
(677 B)
📄
asm_solaris_amd64.s
(423 B)
📄
asm_zos_s390x.s
(8.4 KB)
📄
bluetooth_linux.go
(680 B)
📄
cap_freebsd.go
(5.01 KB)
📄
constants.go
(318 B)
📄
dev_aix_ppc.go
(739 B)
📄
dev_aix_ppc64.go
(858 B)
📄
dev_darwin.go
(747 B)
📄
dev_dragonfly.go
(1.01 KB)
📄
dev_freebsd.go
(1013 B)
📄
dev_linux.go
(1.54 KB)
📄
dev_netbsd.go
(913 B)
📄
dev_openbsd.go
(918 B)
📄
dev_zos.go
(830 B)
📄
dirent.go
(3.01 KB)
📄
endian_big.go
(330 B)
📄
endian_little.go
(358 B)
📄
env_unix.go
(645 B)
📄
epoll_zos.go
(5.02 KB)
📄
fcntl.go
(1.05 KB)
📄
fcntl_darwin.go
(806 B)
📄
fcntl_linux_32bit.go
(436 B)
📄
fdset.go
(781 B)
📄
fstatfs_zos.go
(4.07 KB)
📄
gccgo.go
(1.91 KB)
📄
gccgo_c.c
(1.49 KB)
📄
gccgo_linux_amd64.go
(436 B)
📄
ifreq_linux.go
(4.27 KB)
📄
ioctl_linux.go
(8.07 KB)
📄
ioctl_signed.go
(2.2 KB)
📄
ioctl_unsigned.go
(2.26 KB)
📄
ioctl_zos.go
(2.03 KB)
📄
mkall.sh
(8.11 KB)
📄
mkerrors.sh
(19.56 KB)
📄
mmap_nomremap.go
(336 B)
📄
mremap.go
(1.36 KB)
📄
pagesize_unix.go
(389 B)
📄
pledge_openbsd.go
(2.33 KB)
📄
ptrace_darwin.go
(315 B)
📄
ptrace_ios.go
(284 B)
📄
race.go
(629 B)
📄
race0.go
(553 B)
📄
readdirent_getdents.go
(401 B)
📄
readdirent_getdirentries.go
(698 B)
📄
sockcmsg_dragonfly.go
(544 B)
📄
sockcmsg_linux.go
(2.6 KB)
📄
sockcmsg_unix.go
(3.14 KB)
📄
sockcmsg_unix_other.go
(1.2 KB)
📄
syscall.go
(2.81 KB)
📄
syscall_aix.go
(16.1 KB)
📄
syscall_aix_ppc.go
(1.27 KB)
📄
syscall_aix_ppc64.go
(1.9 KB)
📄
syscall_bsd.go
(14.96 KB)
📄
syscall_darwin.go
(20.72 KB)
📄
syscall_darwin_amd64.go
(1.49 KB)
📄
syscall_darwin_arm64.go
(1.41 KB)
📄
syscall_darwin_libSystem.go
(1.21 KB)
📄
syscall_dragonfly.go
(11.18 KB)
📄
syscall_dragonfly_amd64.go
(1.25 KB)
📄
syscall_freebsd.go
(15.34 KB)
📄
syscall_freebsd_386.go
(1.48 KB)
📄
syscall_freebsd_amd64.go
(1.44 KB)
📄
syscall_freebsd_arm.go
(1.35 KB)
📄
syscall_freebsd_arm64.go
(1.31 KB)
📄
syscall_freebsd_riscv64.go
(1.32 KB)
📄
syscall_hurd.go
(635 B)
📄
syscall_hurd_386.go
(447 B)
📄
syscall_illumos.go
(1.76 KB)
📄
syscall_linux.go
(74.41 KB)
📄
syscall_linux_386.go
(8.88 KB)
📄
syscall_linux_alarm.go
(440 B)
📄
syscall_linux_amd64.go
(5.28 KB)
📄
syscall_linux_amd64_gc.go
(290 B)
📄
syscall_linux_arm.go
(6.94 KB)
📄
syscall_linux_arm64.go
(5.97 KB)
📄
syscall_linux_gc.go
(495 B)
📄
syscall_linux_gc_386.go
(585 B)
📄
syscall_linux_gc_arm.go
(411 B)
📄
syscall_linux_gccgo_386.go
(986 B)
📄
syscall_linux_gccgo_arm.go
(596 B)
📄
syscall_linux_loong64.go
(6.66 KB)
📄
syscall_linux_mips64x.go
(5.83 KB)
📄
syscall_linux_mipsx.go
(5.81 KB)
📄
syscall_linux_ppc.go
(6.85 KB)
📄
syscall_linux_ppc64x.go
(4.98 KB)
📄
syscall_linux_riscv64.go
(6.13 KB)
📄
syscall_linux_s390x.go
(9.29 KB)
📄
syscall_linux_sparc64.go
(4.37 KB)
📄
syscall_netbsd.go
(12.35 KB)
📄
syscall_netbsd_386.go
(819 B)
📄
syscall_netbsd_amd64.go
(814 B)
📄
syscall_netbsd_arm.go
(819 B)
📄
syscall_netbsd_arm64.go
(814 B)
📄
syscall_openbsd.go
(11.04 KB)
📄
syscall_openbsd_386.go
(1000 B)
📄
syscall_openbsd_amd64.go
(990 B)
📄
syscall_openbsd_arm.go
(1000 B)
📄
syscall_openbsd_arm64.go
(990 B)
📄
syscall_openbsd_libc.go
(1.1 KB)
📄
syscall_openbsd_mips64.go
(955 B)
📄
syscall_openbsd_ppc64.go
(990 B)
📄
syscall_openbsd_riscv64.go
(994 B)
📄
syscall_solaris.go
(31.11 KB)
📄
syscall_solaris_amd64.go
(593 B)
📄
syscall_unix.go
(16.45 KB)
📄
syscall_unix_gc.go
(640 B)
📄
syscall_unix_gc_ppc64x.go
(786 B)
📄
syscall_zos_s390x.go
(52.88 KB)
📄
sysvshm_linux.go
(521 B)
📄
sysvshm_unix.go
(1.42 KB)
📄
sysvshm_unix_other.go
(398 B)
📄
timestruct.go
(2.2 KB)
📄
unveil_openbsd.go
(1.19 KB)
📄
xattr_bsd.go
(5.66 KB)
📄
zerrors_aix_ppc.go
(52.42 KB)
📄
zerrors_aix_ppc64.go
(52.67 KB)
📄
zerrors_darwin_amd64.go
(87.45 KB)
📄
zerrors_darwin_arm64.go
(87.45 KB)
📄
zerrors_dragonfly_amd64.go
(70.7 KB)
📄
zerrors_freebsd_386.go
(79.55 KB)
📄
zerrors_freebsd_amd64.go
(79.44 KB)
📄
zerrors_freebsd_arm.go
(79.19 KB)
📄
zerrors_freebsd_arm64.go
(79.22 KB)
📄
zerrors_freebsd_riscv64.go
(83.75 KB)
📄
zerrors_linux.go
(180.01 KB)
📄
zerrors_linux_386.go
(33.98 KB)
📄
zerrors_linux_amd64.go
(34 KB)
📄
zerrors_linux_arm.go
(34.22 KB)
📄
zerrors_linux_arm64.go
(34.05 KB)
📄
zerrors_linux_loong64.go
(33.73 KB)
📄
zerrors_linux_mips.go
(34.54 KB)
📄
zerrors_linux_mips64.go
(34.54 KB)
📄
zerrors_linux_mips64le.go
(34.55 KB)
📄
zerrors_linux_mipsle.go
(34.54 KB)
📄
zerrors_linux_ppc.go
(36.62 KB)
📄
zerrors_linux_ppc64.go
(36.79 KB)
📄
zerrors_linux_ppc64le.go
(36.8 KB)
📄
zerrors_linux_riscv64.go
(33.59 KB)
📄
zerrors_linux_s390x.go
(36.53 KB)
📄
zerrors_linux_sparc64.go
(38.61 KB)
📄
zerrors_netbsd_386.go
(72.76 KB)
📄
zerrors_netbsd_amd64.go
(72.35 KB)
📄
zerrors_netbsd_arm.go
(71.89 KB)
📄
zerrors_netbsd_arm64.go
(72.35 KB)
📄
zerrors_openbsd_386.go
(78.55 KB)
📄
zerrors_openbsd_amd64.go
(78.55 KB)
📄
zerrors_openbsd_arm.go
(78.54 KB)
📄
zerrors_openbsd_arm64.go
(78.55 KB)
📄
zerrors_openbsd_mips64.go
(78.55 KB)
📄
zerrors_openbsd_ppc64.go
(78.51 KB)
📄
zerrors_openbsd_riscv64.go
(78.47 KB)
📄
zerrors_solaris_amd64.go
(59 KB)
📄
zerrors_zos_s390x.go
(34.47 KB)
📄
zptrace_armnn_linux.go
(1.17 KB)
📄
zptrace_linux_arm64.go
(721 B)
📄
zptrace_mipsnn_linux.go
(1.36 KB)
📄
zptrace_mipsnnle_linux.go
(1.41 KB)
📄
zptrace_x86_linux.go
(1.81 KB)
📄
zsyscall_aix_ppc.go
(35.68 KB)
📄
zsyscall_aix_ppc64.go
(30.04 KB)
📄
zsyscall_aix_ppc64_gc.go
(42.43 KB)
📄
zsyscall_aix_ppc64_gccgo.go
(30.85 KB)
📄
zsyscall_darwin_amd64.go
(66.74 KB)
📄
zsyscall_darwin_amd64.s
(29.28 KB)
📄
zsyscall_darwin_arm64.go
(66.69 KB)
📄
zsyscall_darwin_arm64.s
(29.21 KB)
📄
zsyscall_dragonfly_amd64.go
(38.79 KB)
📄
zsyscall_freebsd_386.go
(45.09 KB)
📄
zsyscall_freebsd_amd64.go
(44.9 KB)
📄
zsyscall_freebsd_arm.go
(45.13 KB)
📄
zsyscall_freebsd_arm64.go
(44.9 KB)
📄
zsyscall_freebsd_riscv64.go
(44.91 KB)
📄
zsyscall_illumos_amd64.go
(2.63 KB)
📄
zsyscall_linux.go
(54.29 KB)
📄
zsyscall_linux_386.go
(12.11 KB)
📄
zsyscall_linux_amd64.go
(16.5 KB)
📄
zsyscall_linux_arm.go
(15.61 KB)
📄
zsyscall_linux_arm64.go
(14.22 KB)
📄
zsyscall_linux_loong64.go
(12.61 KB)
📄
zsyscall_linux_mips.go
(16.76 KB)
📄
zsyscall_linux_mips64.go
(16.27 KB)
📄
zsyscall_linux_mips64le.go
(16.01 KB)
📄
zsyscall_linux_mipsle.go
(16.76 KB)
📄
zsyscall_linux_ppc.go
(16.83 KB)
📄
zsyscall_linux_ppc64.go
(17.79 KB)
📄
zsyscall_linux_ppc64le.go
(17.79 KB)
📄
zsyscall_linux_riscv64.go
(14.2 KB)
📄
zsyscall_linux_s390x.go
(12.11 KB)
📄
zsyscall_linux_sparc64.go
(16.43 KB)
📄
zsyscall_netbsd_386.go
(44.13 KB)
📄
zsyscall_netbsd_amd64.go
(43.94 KB)
📄
zsyscall_netbsd_arm.go
(44.13 KB)
📄
zsyscall_netbsd_arm64.go
(43.94 KB)
📄
zsyscall_openbsd_386.go
(57.67 KB)
📄
zsyscall_openbsd_386.s
(26.7 KB)
📄
zsyscall_openbsd_amd64.go
(57.52 KB)
📄
zsyscall_openbsd_amd64.s
(26.7 KB)
📄
zsyscall_openbsd_arm.go
(57.69 KB)
📄
zsyscall_openbsd_arm.s
(26.7 KB)
📄
zsyscall_openbsd_arm64.go
(57.52 KB)
📄
zsyscall_openbsd_arm64.s
(26.7 KB)
📄
zsyscall_openbsd_mips64.go
(57.52 KB)
📄
zsyscall_openbsd_mips64.s
(26.7 KB)
📄
zsyscall_openbsd_ppc64.go
(57.52 KB)
📄
zsyscall_openbsd_ppc64.s
(27.51 KB)
📄
zsyscall_openbsd_riscv64.go
(57.53 KB)
📄
zsyscall_openbsd_riscv64.s
(26.7 KB)
📄
zsyscall_solaris_amd64.go
(59.74 KB)
📄
zsyscall_zos_s390x.go
(29.82 KB)
📄
zsysctl_openbsd_386.go
(11.93 KB)
📄
zsysctl_openbsd_amd64.go
(11.93 KB)
📄
zsysctl_openbsd_arm.go
(11.93 KB)
📄
zsysctl_openbsd_arm64.go
(11.93 KB)
📄
zsysctl_openbsd_mips64.go
(11.93 KB)
📄
zsysctl_openbsd_ppc64.go
(11.93 KB)
📄
zsysctl_openbsd_riscv64.go
(11.97 KB)
📄
zsysnum_darwin_amd64.go
(17.84 KB)
📄
zsysnum_darwin_arm64.go
(17.76 KB)
📄
zsysnum_dragonfly_amd64.go
(27.61 KB)
📄
zsysnum_freebsd_386.go
(36.09 KB)
📄
zsysnum_freebsd_amd64.go
(36.1 KB)
📄
zsysnum_freebsd_arm.go
(36.09 KB)
📄
zsysnum_freebsd_arm64.go
(36.1 KB)
📄
zsysnum_freebsd_riscv64.go
(36.1 KB)
📄
zsysnum_linux_386.go
(17.38 KB)
📄
zsysnum_linux_amd64.go
(12.59 KB)
📄
zsysnum_linux_arm.go
(15.99 KB)
📄
zsysnum_linux_arm64.go
(10.69 KB)
📄
zsysnum_linux_loong64.go
(10.48 KB)
📄
zsysnum_linux_mips.go
(17.27 KB)
📄
zsysnum_linux_mips64.go
(12.74 KB)
📄
zsysnum_linux_mips64le.go
(12.74 KB)
📄
zsysnum_linux_mipsle.go
(17.28 KB)
📄
zsysnum_linux_ppc.go
(17.02 KB)
📄
zsysnum_linux_ppc64.go
(13.95 KB)
📄
zsysnum_linux_ppc64le.go
(13.96 KB)
📄
zsysnum_linux_riscv64.go
(10.71 KB)
📄
zsysnum_linux_s390x.go
(12.84 KB)
📄
zsysnum_linux_sparc64.go
(13.26 KB)
📄
zsysnum_netbsd_386.go
(25.72 KB)
📄
zsysnum_netbsd_amd64.go
(25.73 KB)
📄
zsysnum_netbsd_arm.go
(25.72 KB)
📄
zsysnum_netbsd_arm64.go
(25.71 KB)
📄
zsysnum_openbsd_386.go
(17.91 KB)
📄
zsysnum_openbsd_amd64.go
(17.91 KB)
📄
zsysnum_openbsd_arm.go
(17.91 KB)
📄
zsysnum_openbsd_arm64.go
(17.82 KB)
📄
zsysnum_openbsd_mips64.go
(18.05 KB)
📄
zsysnum_openbsd_ppc64.go
(17.76 KB)
📄
zsysnum_openbsd_riscv64.go
(17.83 KB)
📄
zsysnum_zos_s390x.go
(116.99 KB)
📄
ztypes_aix_ppc.go
(4.91 KB)
📄
ztypes_aix_ppc64.go
(4.98 KB)
📄
ztypes_darwin_amd64.go
(12.4 KB)
📄
ztypes_darwin_arm64.go
(12.4 KB)
📄
ztypes_dragonfly_amd64.go
(6.91 KB)
📄
ztypes_freebsd_386.go
(9.63 KB)
📄
ztypes_freebsd_amd64.go
(9.68 KB)
📄
ztypes_freebsd_arm.go
(9.5 KB)
📄
ztypes_freebsd_arm64.go
(9.39 KB)
📄
ztypes_freebsd_riscv64.go
(9.46 KB)
📄
ztypes_linux.go
(246.65 KB)
📄
ztypes_linux_386.go
(12.37 KB)
📄
ztypes_linux_amd64.go
(12.56 KB)
📄
ztypes_linux_arm.go
(12.33 KB)
📄
ztypes_linux_arm64.go
(12.21 KB)
📄
ztypes_linux_loong64.go
(12.23 KB)
📄
ztypes_linux_mips.go
(12.39 KB)
📄
ztypes_linux_mips64.go
(12.26 KB)
📄
ztypes_linux_mips64le.go
(12.27 KB)
📄
ztypes_linux_mipsle.go
(12.4 KB)
📄
ztypes_linux_ppc.go
(12.57 KB)
📄
ztypes_linux_ppc64.go
(12.4 KB)
📄
ztypes_linux_ppc64le.go
(12.41 KB)
📄
ztypes_linux_riscv64.go
(13.44 KB)
📄
ztypes_linux_s390x.go
(12.7 KB)
📄
ztypes_linux_sparc64.go
(12.26 KB)
📄
ztypes_netbsd_386.go
(9.46 KB)
📄
ztypes_netbsd_amd64.go
(9.65 KB)
📄
ztypes_netbsd_arm.go
(9.59 KB)
📄
ztypes_netbsd_arm64.go
(9.65 KB)
📄
ztypes_openbsd_386.go
(9.24 KB)
📄
ztypes_openbsd_amd64.go
(9.25 KB)
📄
ztypes_openbsd_arm.go
(9.38 KB)
📄
ztypes_openbsd_arm64.go
(9.26 KB)
📄
ztypes_openbsd_mips64.go
(9.26 KB)
📄
ztypes_openbsd_ppc64.go
(9.28 KB)
📄
ztypes_openbsd_riscv64.go
(9.29 KB)
📄
ztypes_solaris_amd64.go
(7.53 KB)
📄
ztypes_zos_s390x.go
(6.66 KB)
Editing: syscall_unix.go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris package unix import ( "bytes" "sort" "sync" "syscall" "unsafe" ) var ( Stdin = 0 Stdout = 1 Stderr = 2 ) // Do the interface allocations only once for common // Errno values. var ( errEAGAIN error = syscall.EAGAIN errEINVAL error = syscall.EINVAL errENOENT error = syscall.ENOENT ) var ( signalNameMapOnce sync.Once signalNameMap map[string]syscall.Signal ) // errnoErr returns common boxed Errno values, to prevent // allocations at runtime. func errnoErr(e syscall.Errno) error { switch e { case 0: return nil case EAGAIN: return errEAGAIN case EINVAL: return errEINVAL case ENOENT: return errENOENT } return e } // ErrnoName returns the error name for error number e. func ErrnoName(e syscall.Errno) string { i := sort.Search(len(errorList), func(i int) bool { return errorList[i].num >= e }) if i < len(errorList) && errorList[i].num == e { return errorList[i].name } return "" } // SignalName returns the signal name for signal number s. func SignalName(s syscall.Signal) string { i := sort.Search(len(signalList), func(i int) bool { return signalList[i].num >= s }) if i < len(signalList) && signalList[i].num == s { return signalList[i].name } return "" } // SignalNum returns the syscall.Signal for signal named s, // or 0 if a signal with such name is not found. // The signal name should start with "SIG". func SignalNum(s string) syscall.Signal { signalNameMapOnce.Do(func() { signalNameMap = make(map[string]syscall.Signal, len(signalList)) for _, signal := range signalList { signalNameMap[signal.name] = signal.num } }) return signalNameMap[s] } // clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte. func clen(n []byte) int { i := bytes.IndexByte(n, 0) if i == -1 { i = len(n) } return i } // Mmap manager, for use by operating system-specific implementations. type mmapper struct { sync.Mutex active map[*byte][]byte // active mappings; key is last byte in mapping mmap func(addr, length uintptr, prot, flags, fd int, offset int64) (uintptr, error) munmap func(addr uintptr, length uintptr) error } func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { if length <= 0 { return nil, EINVAL } // Map the requested memory. addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset) if errno != nil { return nil, errno } // Use unsafe to convert addr into a []byte. b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), length) // Register mapping in m and return it. p := &b[cap(b)-1] m.Lock() defer m.Unlock() m.active[p] = b return b, nil } func (m *mmapper) Munmap(data []byte) (err error) { if len(data) == 0 || len(data) != cap(data) { return EINVAL } // Find the base of the mapping. p := &data[cap(data)-1] m.Lock() defer m.Unlock() b := m.active[p] if b == nil || &b[0] != &data[0] { return EINVAL } // Unmap the memory and update m. if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))); errno != nil { return errno } delete(m.active, p) return nil } func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { return mapper.Mmap(fd, offset, length, prot, flags) } func Munmap(b []byte) (err error) { return mapper.Munmap(b) } func Read(fd int, p []byte) (n int, err error) { n, err = read(fd, p) if raceenabled { if n > 0 { raceWriteRange(unsafe.Pointer(&p[0]), n) } if err == nil { raceAcquire(unsafe.Pointer(&ioSync)) } } return } func Write(fd int, p []byte) (n int, err error) { if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) } n, err = write(fd, p) if raceenabled && n > 0 { raceReadRange(unsafe.Pointer(&p[0]), n) } return } func Pread(fd int, p []byte, offset int64) (n int, err error) { n, err = pread(fd, p, offset) if raceenabled { if n > 0 { raceWriteRange(unsafe.Pointer(&p[0]), n) } if err == nil { raceAcquire(unsafe.Pointer(&ioSync)) } } return } func Pwrite(fd int, p []byte, offset int64) (n int, err error) { if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) } n, err = pwrite(fd, p, offset) if raceenabled && n > 0 { raceReadRange(unsafe.Pointer(&p[0]), n) } return } // For testing: clients can set this flag to force // creation of IPv6 sockets to return EAFNOSUPPORT. var SocketDisableIPv6 bool // Sockaddr represents a socket address. type Sockaddr interface { sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) // lowercase; only we can define Sockaddrs } // SockaddrInet4 implements the Sockaddr interface for AF_INET type sockets. type SockaddrInet4 struct { Port int Addr [4]byte raw RawSockaddrInet4 } // SockaddrInet6 implements the Sockaddr interface for AF_INET6 type sockets. type SockaddrInet6 struct { Port int ZoneId uint32 Addr [16]byte raw RawSockaddrInet6 } // SockaddrUnix implements the Sockaddr interface for AF_UNIX type sockets. type SockaddrUnix struct { Name string raw RawSockaddrUnix } func Bind(fd int, sa Sockaddr) (err error) { ptr, n, err := sa.sockaddr() if err != nil { return err } return bind(fd, ptr, n) } func Connect(fd int, sa Sockaddr) (err error) { ptr, n, err := sa.sockaddr() if err != nil { return err } return connect(fd, ptr, n) } func Getpeername(fd int) (sa Sockaddr, err error) { var rsa RawSockaddrAny var len _Socklen = SizeofSockaddrAny if err = getpeername(fd, &rsa, &len); err != nil { return } return anyToSockaddr(fd, &rsa) } func GetsockoptByte(fd, level, opt int) (value byte, err error) { var n byte vallen := _Socklen(1) err = getsockopt(fd, level, opt, unsafe.Pointer(&n), &vallen) return n, err } func GetsockoptInt(fd, level, opt int) (value int, err error) { var n int32 vallen := _Socklen(4) err = getsockopt(fd, level, opt, unsafe.Pointer(&n), &vallen) return int(n), err } func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error) { vallen := _Socklen(4) err = getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen) return value, err } func GetsockoptIPMreq(fd, level, opt int) (*IPMreq, error) { var value IPMreq vallen := _Socklen(SizeofIPMreq) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptIPv6Mreq(fd, level, opt int) (*IPv6Mreq, error) { var value IPv6Mreq vallen := _Socklen(SizeofIPv6Mreq) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) { var value IPv6MTUInfo vallen := _Socklen(SizeofIPv6MTUInfo) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptICMPv6Filter(fd, level, opt int) (*ICMPv6Filter, error) { var value ICMPv6Filter vallen := _Socklen(SizeofICMPv6Filter) err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) return &value, err } func GetsockoptLinger(fd, level, opt int) (*Linger, error) { var linger Linger vallen := _Socklen(SizeofLinger) err := getsockopt(fd, level, opt, unsafe.Pointer(&linger), &vallen) return &linger, err } func GetsockoptTimeval(fd, level, opt int) (*Timeval, error) { var tv Timeval vallen := _Socklen(unsafe.Sizeof(tv)) err := getsockopt(fd, level, opt, unsafe.Pointer(&tv), &vallen) return &tv, err } func GetsockoptUint64(fd, level, opt int) (value uint64, err error) { var n uint64 vallen := _Socklen(8) err = getsockopt(fd, level, opt, unsafe.Pointer(&n), &vallen) return n, err } func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error) { var rsa RawSockaddrAny var len _Socklen = SizeofSockaddrAny if n, err = recvfrom(fd, p, flags, &rsa, &len); err != nil { return } if rsa.Addr.Family != AF_UNSPEC { from, err = anyToSockaddr(fd, &rsa) } return } // Recvmsg receives a message from a socket using the recvmsg system call. The // received non-control data will be written to p, and any "out of band" // control data will be written to oob. The flags are passed to recvmsg. // // The results are: // - n is the number of non-control data bytes read into p // - oobn is the number of control data bytes read into oob; this may be interpreted using [ParseSocketControlMessage] // - recvflags is flags returned by recvmsg // - from is the address of the sender // // If the underlying socket type is not SOCK_DGRAM, a received message // containing oob data and a single '\0' of non-control data is treated as if // the message contained only control data, i.e. n will be zero on return. func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { var iov [1]Iovec if len(p) > 0 { iov[0].Base = &p[0] iov[0].SetLen(len(p)) } var rsa RawSockaddrAny n, oobn, recvflags, err = recvmsgRaw(fd, iov[:], oob, flags, &rsa) // source address is only specified if the socket is unconnected if rsa.Addr.Family != AF_UNSPEC { from, err = anyToSockaddr(fd, &rsa) } return } // RecvmsgBuffers receives a message from a socket using the recvmsg system // call. This function is equivalent to Recvmsg, but non-control data read is // scattered into the buffers slices. func RecvmsgBuffers(fd int, buffers [][]byte, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { iov := make([]Iovec, len(buffers)) for i := range buffers { if len(buffers[i]) > 0 { iov[i].Base = &buffers[i][0] iov[i].SetLen(len(buffers[i])) } else { iov[i].Base = (*byte)(unsafe.Pointer(&_zero)) } } var rsa RawSockaddrAny n, oobn, recvflags, err = recvmsgRaw(fd, iov, oob, flags, &rsa) if err == nil && rsa.Addr.Family != AF_UNSPEC { from, err = anyToSockaddr(fd, &rsa) } return } // Sendmsg sends a message on a socket to an address using the sendmsg system // call. This function is equivalent to SendmsgN, but does not return the // number of bytes actually sent. func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { _, err = SendmsgN(fd, p, oob, to, flags) return } // SendmsgN sends a message on a socket to an address using the sendmsg system // call. p contains the non-control data to send, and oob contains the "out of // band" control data. The flags are passed to sendmsg. The number of // non-control bytes actually written to the socket is returned. // // Some socket types do not support sending control data without accompanying // non-control data. If p is empty, and oob contains control data, and the // underlying socket type is not SOCK_DGRAM, p will be treated as containing a // single '\0' and the return value will indicate zero bytes sent. // // The Go function Recvmsg, if called with an empty p and a non-empty oob, // will read and ignore this additional '\0'. If the message is received by // code that does not use Recvmsg, or that does not use Go at all, that code // will need to be written to expect and ignore the additional '\0'. // // If you need to send non-empty oob with p actually empty, and if the // underlying socket type supports it, you can do so via a raw system call as // follows: // // msg := &unix.Msghdr{ // Control: &oob[0], // } // msg.SetControllen(len(oob)) // n, _, errno := unix.Syscall(unix.SYS_SENDMSG, uintptr(fd), uintptr(unsafe.Pointer(msg)), flags) func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { var iov [1]Iovec if len(p) > 0 { iov[0].Base = &p[0] iov[0].SetLen(len(p)) } var ptr unsafe.Pointer var salen _Socklen if to != nil { ptr, salen, err = to.sockaddr() if err != nil { return 0, err } } return sendmsgN(fd, iov[:], oob, ptr, salen, flags) } // SendmsgBuffers sends a message on a socket to an address using the sendmsg // system call. This function is equivalent to SendmsgN, but the non-control // data is gathered from buffers. func SendmsgBuffers(fd int, buffers [][]byte, oob []byte, to Sockaddr, flags int) (n int, err error) { iov := make([]Iovec, len(buffers)) for i := range buffers { if len(buffers[i]) > 0 { iov[i].Base = &buffers[i][0] iov[i].SetLen(len(buffers[i])) } else { iov[i].Base = (*byte)(unsafe.Pointer(&_zero)) } } var ptr unsafe.Pointer var salen _Socklen if to != nil { ptr, salen, err = to.sockaddr() if err != nil { return 0, err } } return sendmsgN(fd, iov, oob, ptr, salen, flags) } func Send(s int, buf []byte, flags int) (err error) { return sendto(s, buf, flags, nil, 0) } func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error) { var ptr unsafe.Pointer var salen _Socklen if to != nil { ptr, salen, err = to.sockaddr() if err != nil { return err } } return sendto(fd, p, flags, ptr, salen) } func SetsockoptByte(fd, level, opt int, value byte) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(&value), 1) } func SetsockoptInt(fd, level, opt int, value int) (err error) { var n = int32(value) return setsockopt(fd, level, opt, unsafe.Pointer(&n), 4) } func SetsockoptInet4Addr(fd, level, opt int, value [4]byte) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(&value[0]), 4) } func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(mreq), SizeofIPMreq) } func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(mreq), SizeofIPv6Mreq) } func SetsockoptICMPv6Filter(fd, level, opt int, filter *ICMPv6Filter) error { return setsockopt(fd, level, opt, unsafe.Pointer(filter), SizeofICMPv6Filter) } func SetsockoptLinger(fd, level, opt int, l *Linger) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(l), SizeofLinger) } func SetsockoptString(fd, level, opt int, s string) (err error) { var p unsafe.Pointer if len(s) > 0 { p = unsafe.Pointer(&[]byte(s)[0]) } return setsockopt(fd, level, opt, p, uintptr(len(s))) } func SetsockoptTimeval(fd, level, opt int, tv *Timeval) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(tv), unsafe.Sizeof(*tv)) } func SetsockoptUint64(fd, level, opt int, value uint64) (err error) { return setsockopt(fd, level, opt, unsafe.Pointer(&value), 8) } func Socket(domain, typ, proto int) (fd int, err error) { if domain == AF_INET6 && SocketDisableIPv6 { return -1, EAFNOSUPPORT } fd, err = socket(domain, typ, proto) return } func Socketpair(domain, typ, proto int) (fd [2]int, err error) { var fdx [2]int32 err = socketpair(domain, typ, proto, &fdx) if err == nil { fd[0] = int(fdx[0]) fd[1] = int(fdx[1]) } return } var ioSync int64 func CloseOnExec(fd int) { fcntl(fd, F_SETFD, FD_CLOEXEC) } func SetNonblock(fd int, nonblocking bool) (err error) { flag, err := fcntl(fd, F_GETFL, 0) if err != nil { return err } if (flag&O_NONBLOCK != 0) == nonblocking { return nil } if nonblocking { flag |= O_NONBLOCK } else { flag &= ^O_NONBLOCK } _, err = fcntl(fd, F_SETFL, flag) return err } // Exec calls execve(2), which replaces the calling executable in the process // tree. argv0 should be the full path to an executable ("/bin/ls") and the // executable name should also be the first argument in argv (["ls", "-l"]). // envv are the environment variables that should be passed to the new // process (["USER=go", "PWD=/tmp"]). func Exec(argv0 string, argv []string, envv []string) error { return syscall.Exec(argv0, argv, envv) } // Lutimes sets the access and modification times tv on path. If path refers to // a symlink, it is not dereferenced and the timestamps are set on the symlink. // If tv is nil, the access and modification times are set to the current time. // Otherwise tv must contain exactly 2 elements, with access time as the first // element and modification time as the second element. func Lutimes(path string, tv []Timeval) error { if tv == nil { return UtimesNanoAt(AT_FDCWD, path, nil, AT_SYMLINK_NOFOLLOW) } if len(tv) != 2 { return EINVAL } ts := []Timespec{ NsecToTimespec(TimevalToNsec(tv[0])), NsecToTimespec(TimevalToNsec(tv[1])), } return UtimesNanoAt(AT_FDCWD, path, ts, AT_SYMLINK_NOFOLLOW) } // emptyIovecs reports whether there are no bytes in the slice of Iovec. func emptyIovecs(iov []Iovec) bool { for i := range iov { if iov[i].Len > 0 { return false } } return true } // Setrlimit sets a resource limit. func Setrlimit(resource int, rlim *Rlimit) error { // Just call the syscall version, because as of Go 1.21 // it will affect starting a new process. return syscall.Setrlimit(resource, (*syscall.Rlimit)(rlim)) }
Upload File
Create Folder