libgo: Update to Go 1.3 release.
[official-gcc.git] / libgo / go / syscall / syscall.go
blobc4f2125140efc00fd78ec18ace122b509eac7dfe
1 // 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.
5 // Package syscall contains an interface to the low-level operating system
6 // primitives. The details vary depending on the underlying system, and
7 // by default, godoc will display the syscall documentation for the current
8 // system. If you want godoc to display syscall documentation for another
9 // system, set $GOOS and $GOARCH to the desired system. For example, if
10 // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
11 // to freebsd and $GOARCH to arm.
12 // The primary use of syscall is inside other packages that provide a more
13 // portable interface to the system, such as "os", "time" and "net". Use
14 // those packages rather than this one if you can.
15 // For details of the functions and data types in this package consult
16 // the manuals for the appropriate operating system.
17 // These calls return err == nil to indicate success; otherwise
18 // err is an operating system error describing the failure.
19 // On most systems, that error has type syscall.Errno.
20 package syscall
22 import "unsafe"
24 // StringByteSlice is deprecated. Use ByteSliceFromString instead.
25 // If s contains a NUL byte this function panics instead of
26 // returning an error.
27 func StringByteSlice(s string) []byte {
28 a, err := ByteSliceFromString(s)
29 if err != nil {
30 panic("syscall: string with NUL passed to StringByteSlice")
32 return a
35 // ByteSliceFromString returns a NUL-terminated slice of bytes
36 // containing the text of s. If s contains a NUL byte at any
37 // location, it returns (nil, EINVAL).
38 func ByteSliceFromString(s string) ([]byte, error) {
39 for i := 0; i < len(s); i++ {
40 if s[i] == 0 {
41 return nil, EINVAL
44 a := make([]byte, len(s)+1)
45 copy(a, s)
46 return a, nil
49 // StringBytePtr is deprecated. Use BytePtrFromString instead.
50 // If s contains a NUL byte this function panics instead of
51 // returning an error.
52 func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
54 // BytePtrFromString returns a pointer to a NUL-terminated array of
55 // bytes containing the text of s. If s contains a NUL byte at any
56 // location, it returns (nil, EINVAL).
57 func BytePtrFromString(s string) (*byte, error) {
58 a, err := ByteSliceFromString(s)
59 if err != nil {
60 return nil, err
62 return &a[0], nil
65 // Single-word zero for use when we need a valid pointer to 0 bytes.
66 // See mksyscall.pl.
67 var _zero uintptr
69 var dummy *byte
71 const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
73 func (ts *Timespec) Unix() (sec int64, nsec int64) {
74 return int64(ts.Sec), int64(ts.Nsec)
77 func (tv *Timeval) Unix() (sec int64, nsec int64) {
78 return int64(tv.Sec), int64(tv.Usec) * 1000
81 func (ts *Timespec) Nano() int64 {
82 return int64(ts.Sec)*1e9 + int64(ts.Nsec)
85 func (tv *Timeval) Nano() int64 {
86 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000