blob: 823343d5075a8aaa0f339f657145dade50614045 [file] [log] [blame]
Ian Lance Taylordb618ee2019-02-06 19:04:00 -08001// Copyright 2009 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// +build hurd linux
6
7// glibc library calls.
8
9package syscall
10
11import (
12 "internal/race"
13 "unsafe"
14)
15
16//sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
17//__go_openat(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
18
19//sys futimesat(dirfd int, path *byte, times *[2]Timeval) (err error)
20//futimesat(dirfd _C_int, path *byte, times *[2]Timeval) _C_int
21func Futimesat(dirfd int, path string, tv []Timeval) (err error) {
22 if len(tv) != 2 {
23 return EINVAL
24 }
25 return futimesat(dirfd, StringBytePtr(path), (*[2]Timeval)(unsafe.Pointer(&tv[0])))
26}
27
28func Futimes(fd int, tv []Timeval) (err error) {
29 // Believe it or not, this is the best we can do on GNU/Linux
30 // (and is what glibc does).
31 return Utimes("/proc/self/fd/"+itoa(fd), tv)
32}
33
34//sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
Paul E. Murphy6fd64182020-09-15 14:18:28 -050035//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
Ian Lance Taylordb618ee2019-02-06 19:04:00 -080036
37//sys accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd int, err error)
38//accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int
39
40func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
41 var rsa RawSockaddrAny
42 var len Socklen_t = SizeofSockaddrAny
43 nfd, err = accept4(fd, &rsa, &len, flags)
44 if err != nil {
45 return -1, nil, err
46 }
47 sa, err = anyToSockaddr(&rsa)
48 if err != nil {
49 Close(nfd)
50 return -1, nil, err
51 }
52 return nfd, sa, nil
53}
54
55//sysnb Dup3(oldfd int, newfd int, flags int) (err error)
56//dup3(oldfd _C_int, newfd _C_int, flags _C_int) _C_int
57
58//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
59//faccessat(dirfd _C_int, pathname *byte, mode _C_int, flags _C_int) _C_int
60
61//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
62//fallocate(fd _C_int, mode _C_int, offset Offset_t, len Offset_t) _C_int
63
64//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
65//fchmodat(dirfd _C_int, pathname *byte, mode Mode_t, flags _C_int) _C_int
66
67//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
68//fchownat(dirfd _C_int, path *byte, owner Uid_t, group Gid_t, flags _C_int) _C_int
69
70//sys Flock(fd int, how int) (err error)
71//flock(fd _C_int, how _C_int) _C_int
72
73func Getdents(fd int, buf []byte) (n int, err error) {
74 var p *byte
75 if len(buf) > 0 {
76 p = &buf[0]
77 } else {
78 p = (*byte)(unsafe.Pointer(&_zero))
79 }
80 s := SYS_GETDENTS64
81 if s == 0 {
82 s = SYS_GETDENTS
83 }
84 r1, _, errno := Syscall(uintptr(s), uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(buf)))
85 n = int(r1)
86 if n < 0 {
87 err = errno
88 }
89 return
90}
91
92func ReadDirent(fd int, buf []byte) (n int, err error) {
93 return Getdents(fd, buf)
94}
95
96//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
97//mkdirat(dirfd _C_int, path *byte, mode Mode_t) _C_int
98
99//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
100//mknodat(dirfd _C_int, path *byte, mode Mode_t, dev _dev_t) _C_int
101
102//sysnb pipe2(p *[2]_C_int, flags int) (err error)
103//pipe2(p *[2]_C_int, flags _C_int) _C_int
104func Pipe2(p []int, flags int) (err error) {
105 if len(p) != 2 {
106 return EINVAL
107 }
108 var pp [2]_C_int
109 err = pipe2(&pp, flags)
110 p[0] = int(pp[0])
111 p[1] = int(pp[1])
112 return
113}
114
115//sys sendfile(outfd int, infd int, offset *Offset_t, count int) (written int, err error)
116//sendfile64(outfd _C_int, infd _C_int, offset *Offset_t, count Size_t) Ssize_t
117func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
118 if race.Enabled {
119 race.ReleaseMerge(unsafe.Pointer(&ioSync))
120 }
121 var soff Offset_t
122 var psoff *Offset_t
123 if offset != nil {
124 soff = Offset_t(*offset)
125 psoff = &soff
126 }
127 written, err = sendfile(outfd, infd, psoff, count)
128 if offset != nil {
129 *offset = int64(soff)
130 }
131 return
132}
133
134//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
135//sync_file_range(fd _C_int, off Offset_t, n Offset_t, flags _C_uint) _C_int