Debian Codegraph @

libgo/go/syscall/syscall.go

raw
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.
4
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 //
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.
26 package syscall
27
28 import "unsafe"
29
30 //go:generate go run ./mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
31
32 // StringByteSlice converts a string to a NUL-terminated []byte,
33 // If s contains a NUL byte this function panics instead of
34 // returning an error.
35 //
36 // Deprecated: Use ByteSliceFromString instead.
37 func StringByteSlice(s string) []byte {
38 a, err := ByteSliceFromString(s)
39 if err != nil {
40 panic("syscall: string with NUL passed to StringByteSlice")
41 }
42 return a
43 }
44
45 // ByteSliceFromString returns a NUL-terminated slice of bytes
46 // containing the text of s. If s contains a NUL byte at any
47 // location, it returns (nil, EINVAL).
48 func ByteSliceFromString(s string) ([]byte, error) {
49 for i := 0; i < len(s); i++ {
50 if s[i] == 0 {
51 return nil, EINVAL
52 }
53 }
54 a := make([]byte, len(s)+1)
55 copy(a, s)
56 return a, nil
57 }
58
59 // StringBytePtr returns a pointer to a NUL-terminated array of bytes.
60 // If s contains a NUL byte this function panics instead of returning
61 // an error.
62 //
63 // Deprecated: Use BytePtrFromString instead.
64 func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
65
66 // BytePtrFromString returns a pointer to a NUL-terminated array of
67 // bytes containing the text of s. If s contains a NUL byte at any
68 // location, it returns (nil, EINVAL).
69 func BytePtrFromString(s string) (*byte, error) {
70 a, err := ByteSliceFromString(s)
71 if err != nil {
72 return nil, err
73 }
74 return &a[0], nil
75 }
76
77 // Single-word zero for use when we need a valid pointer to 0 bytes.
78 // See mksyscall.pl.
79 var _zero uintptr
80
81 var dummy *byte
82
83 const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
84
85 // Unix returns the time stored in ts as seconds plus nanoseconds.
86 func (ts *Timespec) Unix() (sec int64, nsec int64) {
87 return int64(ts.Sec), int64(ts.Nsec)
88 }
89
90 // Unix returns the time stored in tv as seconds plus nanoseconds.
91 func (tv *Timeval) Unix() (sec int64, nsec int64) {
92 return int64(tv.Sec), int64(tv.Usec) * 1000
93 }
94
95 // Nano returns the time stored in ts as nanoseconds.
96 func (ts *Timespec) Nano() int64 {
97 return int64(ts.Sec)*1e9 + int64(ts.Nsec)
98 }
99
100 // Nano returns the time stored in tv as nanoseconds.
101 func (tv *Timeval) Nano() int64 {
102 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
103 }
104
105 // Getpagesize and Exit are provided by the runtime.
106
107 func Getpagesize() int
108 func Exit(code int)