github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/syscall/syscall.go (about) 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 package syscall 21 22 // StringByteSlice is deprecated. Use ByteSliceFromString instead. 23 // If s contains a NUL byte this function panics instead of 24 // returning an error. 25 func StringByteSlice(s string) []byte { 26 a, err := ByteSliceFromString(s) 27 if err != nil { 28 panic("syscall: string with NUL passed to StringByteSlice") 29 } 30 return a 31 } 32 33 // ByteSliceFromString returns a NUL-terminated slice of bytes 34 // containing the text of s. If s contains a NUL byte at any 35 // location, it returns (nil, EINVAL). 36 func ByteSliceFromString(s string) ([]byte, error) { 37 for i := 0; i < len(s); i++ { 38 if s[i] == 0 { 39 return nil, EINVAL 40 } 41 } 42 a := make([]byte, len(s)+1) 43 copy(a, s) 44 return a, nil 45 } 46 47 // StringBytePtr is deprecated. Use BytePtrFromString instead. 48 // If s contains a NUL byte this function panics instead of 49 // returning an error. 50 func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] } 51 52 // BytePtrFromString returns a pointer to a NUL-terminated array of 53 // bytes containing the text of s. If s contains a NUL byte at any 54 // location, it returns (nil, EINVAL). 55 func BytePtrFromString(s string) (*byte, error) { 56 a, err := ByteSliceFromString(s) 57 if err != nil { 58 return nil, err 59 } 60 return &a[0], nil 61 } 62 63 // Single-word zero for use when we need a valid pointer to 0 bytes. 64 // See mksyscall.pl. 65 var _zero uintptr 66 67 func (ts *Timespec) Unix() (sec int64, nsec int64) { 68 return int64(ts.Sec), int64(ts.Nsec) 69 } 70 71 func (tv *Timeval) Unix() (sec int64, nsec int64) { 72 return int64(tv.Sec), int64(tv.Usec) * 1000 73 } 74 75 func (ts *Timespec) Nano() int64 { 76 return int64(ts.Sec)*1e9 + int64(ts.Nsec) 77 } 78 79 func (tv *Timeval) Nano() int64 { 80 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 81 }