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