OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [syscall/] [libcall_posix.go] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 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
// POSIX library calls.
6
// This file is compiled as ordinary Go code,
7
// but it is also input to mksyscall,
8
// which parses the //sys lines and generates library call stubs.
9
// Note that sometimes we use a lowercase //sys name and
10
// wrap it in our own nicer implementation.
11
 
12
package syscall
13
 
14
import "unsafe"
15
 
16
/*
17
 * Wrapped
18
 */
19
 
20
//sysnb pipe(p *[2]int) (err error)
21
//pipe(p *[2]int) int
22
func Pipe(p []int) (err error) {
23
        if len(p) != 2 {
24
                return EINVAL
25
        }
26
        var pp [2]int
27
        err = pipe(&pp)
28
        p[0] = pp[0]
29
        p[1] = pp[1]
30
        return
31
}
32
 
33
//sys   utimes(path string, times *[2]Timeval) (err error)
34
//utimes(path *byte, times *[2]Timeval) int
35
func Utimes(path string, tv []Timeval) (err error) {
36
        if len(tv) != 2 {
37
                return EINVAL
38
        }
39
        return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
40
}
41
 
42
//sys   getcwd(buf *byte, size Size_t) (err error)
43
//getcwd(buf *byte, size Size_t) *byte
44
 
45
const ImplementsGetwd = true
46
 
47
func Getwd() (ret string, err error) {
48
        for len := Size_t(4096); ; len *= 2 {
49
                b := make([]byte, len)
50
                err := getcwd(&b[0], len)
51
                if err == nil {
52
                        i := 0
53
                        for b[i] != 0 {
54
                                i++
55
                        }
56
                        return string(b[0:i]), nil
57
                }
58
                if err != ERANGE {
59
                        return "", err
60
                }
61
        }
62
}
63
 
64
//sysnb getgroups(size int, list *Gid_t) (nn int, err error)
65
//getgroups(size int, list *Gid_t) int
66
 
67
func Getgroups() (gids []int, err error) {
68
        n, err := getgroups(0, nil)
69
        if err != nil {
70
                return nil, err
71
        }
72
        if n == 0 {
73
                return nil, nil
74
        }
75
 
76
        // Sanity check group count.  Max is 1<<16 on GNU/Linux.
77
        if n < 0 || n > 1<<20 {
78
                return nil, EINVAL
79
        }
80
 
81
        a := make([]Gid_t, n)
82
        n, err = getgroups(n, &a[0])
83
        if err != nil {
84
                return nil, err
85
        }
86
        gids = make([]int, n)
87
        for i, v := range a[0:n] {
88
                gids[i] = int(v)
89
        }
90
        return
91
}
92
 
93
//sysnb setgroups(n int, list *Gid_t) (err error)
94
//setgroups(n Size_t, list *Gid_t) int
95
 
96
func Setgroups(gids []int) (err error) {
97
        if len(gids) == 0 {
98
                return setgroups(0, nil)
99
        }
100
 
101
        a := make([]Gid_t, len(gids))
102
        for i, v := range gids {
103
                a[i] = Gid_t(v)
104
        }
105
        return setgroups(len(a), &a[0])
106
}
107
 
108
type WaitStatus uint32
109
 
110
// The WaitStatus methods are implemented in C, to pick up the macros
111
// #defines in .
112
 
113
func (w WaitStatus) Exited() bool
114
func (w WaitStatus) Signaled() bool
115
func (w WaitStatus) Stopped() bool
116
func (w WaitStatus) Continued() bool
117
func (w WaitStatus) CoreDump() bool
118
func (w WaitStatus) ExitStatus() int
119
func (w WaitStatus) Signal() int
120
func (w WaitStatus) StopSignal() int
121
func (w WaitStatus) TrapCause() int
122
 
123
//sys   Mkfifo(path string, mode uint32) (err error)
124
//mkfifo(path *byte, mode Mode_t) int
125
 
126
//sys   Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
127
//select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) int
128
 
129
const nfdbits = unsafe.Sizeof(fds_bits_type) * 8
130
 
131
type FdSet struct {
132
        Bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]fds_bits_type
133
}
134
 
135
func FDSet(fd int, set *FdSet) {
136
        set.Bits[fd/nfdbits] |= (1 << (uint)(fd%nfdbits))
137
}
138
 
139
func FDClr(fd int, set *FdSet) {
140
        set.Bits[fd/nfdbits] &^= (1 << (uint)(fd%nfdbits))
141
}
142
 
143
func FDIsSet(fd int, set *FdSet) bool {
144
        if set.Bits[fd/nfdbits]&(1<<(uint)(fd%nfdbits)) != 0 {
145
                return true
146
        } else {
147
                return false
148
        }
149
}
150
 
151
func FDZero(set *FdSet) {
152
        for i := range set.Bits {
153
                set.Bits[i] = 0
154
        }
155
}
156
 
157
//sys   Access(path string, mode uint32) (err error)
158
//access(path *byte, mode int) int
159
 
160
//sys   Chdir(path string) (err error)
161
//chdir(path *byte) int
162
 
163
//sys   Chmod(path string, mode uint32) (err error)
164
//chmod(path *byte, mode Mode_t) int
165
 
166
//sys   Chown(path string, uid int, gid int) (err error)
167
//chown(path *byte, uid Uid_t, gid Gid_t) int
168
 
169
//sys   Chroot(path string) (err error)
170
//chroot(path *byte) int
171
 
172
//sys   Close(fd int) (err error)
173
//close(fd int) int
174
 
175
//sys   Creat(path string, mode uint32) (fd int, err error)
176
//creat(path *byte, mode Mode_t) int
177
 
178
//sysnb Dup(oldfd int) (fd int, err error)
179
//dup(oldfd int) int
180
 
181
//sysnb Dup2(oldfd int, newfd int) (err error)
182
//dup2(oldfd int, newfd int) int
183
 
184
//sys   Exit(code int)
185
//exit(code int)
186
 
187
//sys   Fchdir(fd int) (err error)
188
//fchdir(fd int) int
189
 
190
//sys   Fchmod(fd int, mode uint32) (err error)
191
//fchmod(fd int, mode Mode_t) int
192
 
193
//sys   Fchown(fd int, uid int, gid int) (err error)
194
//fchown(fd int, uid Uid_t, gid Gid_t) int
195
 
196
//sys   fcntl(fd int, cmd int, arg int) (val int, err error)
197
//fcntl(fd int, cmd int, arg int) int
198
 
199
//sys   Fdatasync(fd int) (err error)
200
//fdatasync(fd int) int
201
 
202
//sys   Fsync(fd int) (err error)
203
//fsync(fd int) int
204
 
205
//sysnb Getegid() (egid int)
206
//getegid() Gid_t
207
 
208
//sysnb Geteuid() (euid int)
209
//geteuid() Uid_t
210
 
211
//sysnb Getgid() (gid int)
212
//getgid() Gid_t
213
 
214
//sysnb Getpagesize() (pagesize int)
215
//getpagesize() int
216
 
217
//sysnb Getpgid(pid int) (pgid int, err error)
218
//getpgid(pid Pid_t) Pid_t
219
 
220
//sysnb Getpgrp() (pid int)
221
//getpgrp() Pid_t
222
 
223
//sysnb Getpid() (pid int)
224
//getpid() Pid_t
225
 
226
//sysnb Getppid() (ppid int)
227
//getppid() Pid_t
228
 
229
// FIXME: mksysinfo Rlimit
230
// //sysnb      Getrlimit(resource int, rlim *Rlimit) (err error)
231
// //getrlimit(resource int, rlim *Rlimit) int
232
 
233
//sysnb Getrusage(who int, rusage *Rusage) (err error)
234
//getrusage(who int, rusage *Rusage) int
235
 
236
//sysnb gettimeofday(tv *Timeval, tz *byte) (err error)
237
//gettimeofday(tv *Timeval, tz *byte) int
238
func Gettimeofday(tv *Timeval) (err error) {
239
        return gettimeofday(tv, nil)
240
}
241
 
242
//sysnb Getuid() (uid int)
243
//getuid() Uid_t
244
 
245
//sysnb Kill(pid int, sig int) (err error)
246
//kill(pid Pid_t, sig int) int
247
 
248
//sys   Lchown(path string, uid int, gid int) (err error)
249
//lchown(path *byte, uid Uid_t, gid Gid_t) int
250
 
251
//sys   Link(oldpath string, newpath string) (err error)
252
//link(oldpath *byte, newpath *byte) int
253
 
254
//sys   Mkdir(path string, mode uint32) (err error)
255
//mkdir(path *byte, mode Mode_t) int
256
 
257
//sys   Mknod(path string, mode uint32, dev int) (err error)
258
//mknod(path *byte, mode Mode_t, dev _dev_t) int
259
 
260
//sys   Mount(source string, target string, fstype string, flags int, data string) (err error)
261
//mount(source *byte, target *byte, fstype *byte, flags _C_long, data *byte) int
262
 
263
//sys   Nanosleep(time *Timespec, leftover *Timespec) (err error)
264
//nanosleep(time *Timespec, leftover *Timespec) int
265
 
266
//sys   Pause() (err error)
267
//pause() int
268
 
269
//sys   Read(fd int, p []byte) (n int, err error)
270
//read(fd int, buf *byte, count Size_t) Ssize_t
271
 
272
//sys   Readlink(path string, buf []byte) (n int, err error)
273
//readlink(path *byte, buf *byte, bufsiz Size_t) Ssize_t
274
 
275
//sys   Rename(oldpath string, newpath string) (err error)
276
//rename(oldpath *byte, newpath *byte) int
277
 
278
//sys   Rmdir(path string) (err error)
279
//rmdir(path *byte) int
280
 
281
//sys   Setdomainname(p []byte) (err error)
282
//setdomainname(name *byte, len Size_t) int
283
 
284
//sys   Sethostname(p []byte) (err error)
285
//sethostname(name *byte, len Size_t) int
286
 
287
//sysnb Setgid(gid int) (err error)
288
//setgid(gid Gid_t) int
289
 
290
//sysnb Setregid(rgid int, egid int) (err error)
291
//setregid(rgid Gid_t, egid Gid_t) int
292
 
293
//sysnb Setpgid(pid int, pgid int) (err error)
294
//setpgid(pid Pid_t, pgid Pid_t) int
295
 
296
//sysnb Setreuid(ruid int, euid int) (err error)
297
//setreuid(ruid Uid_t, euid Uid_t) int
298
 
299
// FIXME: mksysinfo Rlimit
300
// //sysnb      Setrlimit(resource int, rlim *Rlimit) (err error)
301
// //setrlimit(resource int, rlim *Rlimit) int
302
 
303
//sysnb Setsid() (pid int, err error)
304
//setsid() Pid_t
305
 
306
//sysnb settimeofday(tv *Timeval, tz *byte) (err error)
307
//settimeofday(tv *Timeval, tz *byte) int
308
 
309
func Settimeofday(tv *Timeval) (err error) {
310
        return settimeofday(tv, nil)
311
}
312
 
313
//sysnb Setuid(uid int) (err error)
314
//setuid(uid Uid_t) int
315
 
316
//sys   Symlink(oldpath string, newpath string) (err error)
317
//symlink(oldpath *byte, newpath *byte) int
318
 
319
//sys   Sync()
320
//sync()
321
 
322
// FIXME: mksysinfo Time_t
323
// //sysnb      Time(t *Time_t) (tt Time_t, err error)
324
// //time(t *Time_t) Time_t
325
 
326
//sysnb Times(tms *Tms) (ticks uintptr, err error)
327
//times(tms *Tms) _clock_t
328
 
329
//sysnb Umask(mask int) (oldmask int)
330
//umask(mask Mode_t) Mode_t
331
 
332
//sys   Unlink(path string) (err error)
333
//unlink(path *byte) int
334
 
335
// FIXME: mksysinfo Utimbuf
336
// //sys        Utime(path string, buf *Utimbuf) (err error)
337
// //utime(path *byte, buf *Utimbuf) int
338
 
339
//sys   Write(fd int, p []byte) (n int, err error)
340
//write(fd int, buf *byte, count Size_t) Ssize_t
341
 
342
//sys   munmap(addr uintptr, length uintptr) (err error)
343
//munmap(addr *byte, length Size_t) int
344
 
345
//sys Madvise(b []byte, advice int) (err error)
346
//madvise(addr *byte, len Size_t, advice int) int
347
 
348
//sys   Mprotect(b []byte, prot int) (err error)
349
//mprotect(addr *byte, len Size_t, prot int) int
350
 
351
//sys   Mlock(b []byte) (err error)
352
//mlock(addr *byte, len Size_t) int
353
 
354
//sys   Munlock(b []byte) (err error)
355
//munlock(addr *byte, len Size_t) int
356
 
357
//sys   Mlockall(flags int) (err error)
358
//mlockall(flags int) int
359
 
360
//sys   Munlockall() (err error)
361
//munlockall() int
362
 
363
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
364
 
365
func NsecToTimespec(nsec int64) (ts Timespec) {
366
        ts.Sec = Timespec_sec_t(nsec / 1e9)
367
        ts.Nsec = Timespec_nsec_t(nsec % 1e9)
368
        return
369
}
370
 
371
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
372
 
373
func NsecToTimeval(nsec int64) (tv Timeval) {
374
        nsec += 999 // round up to microsecond
375
        tv.Sec = Timeval_sec_t(nsec / 1e9)
376
        tv.Usec = Timeval_usec_t(nsec % 1e9 / 1e3)
377
        return
378
}
379
 
380
//sysnb Tcgetattr(fd int, p *Termios) (err error)
381
//tcgetattr(fd int, p *Termios) int
382
 
383
//sys   Tcsetattr(fd int, actions int, p *Termios) (err error)
384
//tcsetattr(fd int, actions int, p *Termios) int

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.