Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / syscall / syscall.go
blob4e1187be0a2f1d551564b379b66d0725eee8643d
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 // Deprecated: this package is locked down. Callers should use the
22 // corresponding package in the golang.org/x/sys repository instead.
23 // That is also where updates required by new systems or versions
24 // should be applied. See https://golang.org/s/go1.4-syscall for more
25 // information.
27 package syscall
29 import "unsafe"
31 //go:generate go run golang.org/x/sys/windows/mkwinsyscall -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
33 // StringByteSlice converts a string to a NUL-terminated []byte,
34 // If s contains a NUL byte this function panics instead of
35 // returning an error.
37 // Deprecated: Use ByteSliceFromString instead.
38 func StringByteSlice(s string) []byte {
39 a, err := ByteSliceFromString(s)
40 if err != nil {
41 panic("syscall: string with NUL passed to StringByteSlice")
43 return a
46 // ByteSliceFromString returns a NUL-terminated slice of bytes
47 // containing the text of s. If s contains a NUL byte at any
48 // location, it returns (nil, EINVAL).
49 func ByteSliceFromString(s string) ([]byte, error) {
50 for i := 0; i < len(s); i++ {
51 if s[i] == 0 {
52 return nil, EINVAL
55 a := make([]byte, len(s)+1)
56 copy(a, s)
57 return a, nil
60 // StringBytePtr returns a pointer to a NUL-terminated array of bytes.
61 // If s contains a NUL byte this function panics instead of returning
62 // an error.
64 // Deprecated: Use BytePtrFromString instead.
65 func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
67 // BytePtrFromString returns a pointer to a NUL-terminated array of
68 // bytes containing the text of s. If s contains a NUL byte at any
69 // location, it returns (nil, EINVAL).
70 func BytePtrFromString(s string) (*byte, error) {
71 a, err := ByteSliceFromString(s)
72 if err != nil {
73 return nil, err
75 return &a[0], nil
78 // Single-word zero for use when we need a valid pointer to 0 bytes.
79 // See mksyscall.pl.
80 var _zero uintptr
82 var dummy *byte
84 const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
86 // Unix returns ts as the number of seconds and nanoseconds elapsed since the
87 // Unix epoch.
88 func (ts *Timespec) Unix() (sec int64, nsec int64) {
89 return int64(ts.Sec), int64(ts.Nsec)
92 // Unix returns tv as the number of seconds and nanoseconds elapsed since the
93 // Unix epoch.
94 func (tv *Timeval) Unix() (sec int64, nsec int64) {
95 return int64(tv.Sec), int64(tv.Usec) * 1000
98 // Nano returns ts as the number of nanoseconds elapsed since the Unix epoch.
99 func (ts *Timespec) Nano() int64 {
100 return int64(ts.Sec)*1e9 + int64(ts.Nsec)
103 // Nano returns tv as the number of nanoseconds elapsed since the Unix epoch.
104 func (tv *Timeval) Nano() int64 {
105 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
108 // Getpagesize and Exit are provided by the runtime.
110 func Getpagesize() int
111 func Exit(code int)