* cp-tree.h (build_noexcept_spec, add_exception_specifier): Adjust
[official-gcc.git] / libgo / go / syscall / syscall.go
blob8e785ddfd5d09d24ada83c9b11e9d39353846b74
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.
21 // NOTE: This package is locked down. Code outside the standard
22 // Go repository should be migrated to use the corresponding
23 // package in the golang.org/x/sys repository. That is also where updates
24 // required by new systems or versions should be applied.
25 // Signal, Errno and SysProcAttr are not yet available in
26 // golang.org/x/sys and must still be referenced from the
27 // syscall package. See https://golang.org/s/go1.4-syscall
28 // for more information.
30 package syscall
32 import "unsafe"
34 //go:generate go run mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
36 // StringByteSlice converts a string to a NUL-terminated []byte,
37 // If s contains a NUL byte this function panics instead of
38 // returning an error.
40 // Deprecated: Use ByteSliceFromString instead.
41 func StringByteSlice(s string) []byte {
42 a, err := ByteSliceFromString(s)
43 if err != nil {
44 panic("syscall: string with NUL passed to StringByteSlice")
46 return a
49 // ByteSliceFromString returns a NUL-terminated slice of bytes
50 // containing the text of s. If s contains a NUL byte at any
51 // location, it returns (nil, EINVAL).
52 func ByteSliceFromString(s string) ([]byte, error) {
53 for i := 0; i < len(s); i++ {
54 if s[i] == 0 {
55 return nil, EINVAL
58 a := make([]byte, len(s)+1)
59 copy(a, s)
60 return a, nil
63 // StringBytePtr returns a pointer to a NUL-terminated array of bytes.
64 // If s contains a NUL byte this function panics instead of returning
65 // an error.
67 // Deprecated: Use BytePtrFromString instead.
68 func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
70 // BytePtrFromString returns a pointer to a NUL-terminated array of
71 // bytes containing the text of s. If s contains a NUL byte at any
72 // location, it returns (nil, EINVAL).
73 func BytePtrFromString(s string) (*byte, error) {
74 a, err := ByteSliceFromString(s)
75 if err != nil {
76 return nil, err
78 return &a[0], nil
81 // Single-word zero for use when we need a valid pointer to 0 bytes.
82 // See mksyscall.pl.
83 var _zero uintptr
85 var dummy *byte
87 const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
89 // Unix returns ts as the number of seconds and nanoseconds elapsed since the
90 // Unix epoch.
91 func (ts *Timespec) Unix() (sec int64, nsec int64) {
92 return int64(ts.Sec), int64(ts.Nsec)
95 // Unix returns tv as the number of seconds and nanoseconds elapsed since the
96 // Unix epoch.
97 func (tv *Timeval) Unix() (sec int64, nsec int64) {
98 return int64(tv.Sec), int64(tv.Usec) * 1000
101 // Nano returns ts as the number of nanoseconds elapsed since the Unix epoch.
102 func (ts *Timespec) Nano() int64 {
103 return int64(ts.Sec)*1e9 + int64(ts.Nsec)
106 // Nano returns tv as the number of nanoseconds elapsed since the Unix epoch.
107 func (tv *Timeval) Nano() int64 {
108 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
111 // Getpagesize and Exit are provided by the runtime.
113 func Getpagesize() int
114 func Exit(code int)