1
2
3
4
5
6
7 package unix
8
9 import "unsafe"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
31 var ts *Timespec
32 if timeout != nil {
33 ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
34 }
35 return pselect6(nfd, r, w, e, ts, nil)
36 }
37
38
39
40
41
42
43
44 func Stat(path string, stat *Stat_t) (err error) {
45 return Fstatat(AT_FDCWD, path, stat, 0)
46 }
47
48 func Lchown(path string, uid int, gid int) (err error) {
49 return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
50 }
51
52 func Lstat(path string, stat *Stat_t) (err error) {
53 return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
54 }
55
56
57
58
59
60 func Ustat(dev int, ubuf *Ustat_t) (err error) {
61 return ENOSYS
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 func setTimespec(sec, nsec int64) Timespec {
84 return Timespec{Sec: sec, Nsec: nsec}
85 }
86
87 func setTimeval(sec, usec int64) Timeval {
88 return Timeval{Sec: sec, Usec: usec}
89 }
90
91 func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
92 if tv == nil {
93 return utimensat(dirfd, path, nil, 0)
94 }
95
96 ts := []Timespec{
97 NsecToTimespec(TimevalToNsec(tv[0])),
98 NsecToTimespec(TimevalToNsec(tv[1])),
99 }
100 return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
101 }
102
103 func Time(t *Time_t) (Time_t, error) {
104 var tv Timeval
105 err := Gettimeofday(&tv)
106 if err != nil {
107 return 0, err
108 }
109 if t != nil {
110 *t = Time_t(tv.Sec)
111 }
112 return Time_t(tv.Sec), nil
113 }
114
115 func Utime(path string, buf *Utimbuf) error {
116 tv := []Timeval{
117 {Sec: buf.Actime},
118 {Sec: buf.Modtime},
119 }
120 return Utimes(path, tv)
121 }
122
123 func utimes(path string, tv *[2]Timeval) (err error) {
124 if tv == nil {
125 return utimensat(AT_FDCWD, path, nil, 0)
126 }
127
128 ts := []Timespec{
129 NsecToTimespec(TimevalToNsec(tv[0])),
130 NsecToTimespec(TimevalToNsec(tv[1])),
131 }
132 return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
133 }
134
135
136 func Getrlimit(resource int, rlim *Rlimit) error {
137 err := Prlimit(0, resource, nil, rlim)
138 if err != ENOSYS {
139 return err
140 }
141 return getrlimit(resource, rlim)
142 }
143
144 func (r *PtraceRegs) PC() uint64 { return r.Pc }
145
146 func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
147
148 func (iov *Iovec) SetLen(length int) {
149 iov.Len = uint64(length)
150 }
151
152 func (msghdr *Msghdr) SetControllen(length int) {
153 msghdr.Controllen = uint64(length)
154 }
155
156 func (msghdr *Msghdr) SetIovlen(length int) {
157 msghdr.Iovlen = uint64(length)
158 }
159
160 func (cmsg *Cmsghdr) SetLen(length int) {
161 cmsg.Len = uint64(length)
162 }
163
164 func (rsa *RawSockaddrNFCLLCP) SetServiceNameLen(length int) {
165 rsa.Service_name_len = uint64(length)
166 }
167
168 func Pause() error {
169 _, err := ppoll(nil, 0, nil, nil)
170 return err
171 }
172
173
174
175 func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error {
176 cmdlineLen := len(cmdline)
177 if cmdlineLen > 0 {
178
179
180
181 cmdlineLen++
182 }
183 return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
184 }
185
186 const SYS_FSTATAT = SYS_NEWFSTATAT
187
View as plain text