khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame^] | 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 | // +build windows |
| 6 | |
| 7 | // Package windows contains an interface to the low-level operating system |
| 8 | // primitives. OS details vary depending on the underlying system, and |
| 9 | // by default, godoc will display the OS-specific documentation for the current |
| 10 | // system. If you want godoc to display syscall documentation for another |
| 11 | // system, set $GOOS and $GOARCH to the desired system. For example, if |
| 12 | // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS |
| 13 | // to freebsd and $GOARCH to arm. |
| 14 | // |
| 15 | // The primary use of this package is inside other packages that provide a more |
| 16 | // portable interface to the system, such as "os", "time" and "net". Use |
| 17 | // those packages rather than this one if you can. |
| 18 | // |
| 19 | // For details of the functions and data types in this package consult |
| 20 | // the manuals for the appropriate operating system. |
| 21 | // |
| 22 | // These calls return err == nil to indicate success; otherwise |
| 23 | // err represents an operating system error describing the failure and |
| 24 | // holds a value of type syscall.Errno. |
| 25 | package windows // import "golang.org/x/sys/windows" |
| 26 | |
| 27 | import ( |
| 28 | "syscall" |
| 29 | ) |
| 30 | |
| 31 | // ByteSliceFromString returns a NUL-terminated slice of bytes |
| 32 | // containing the text of s. If s contains a NUL byte at any |
| 33 | // location, it returns (nil, syscall.EINVAL). |
| 34 | func ByteSliceFromString(s string) ([]byte, error) { |
| 35 | for i := 0; i < len(s); i++ { |
| 36 | if s[i] == 0 { |
| 37 | return nil, syscall.EINVAL |
| 38 | } |
| 39 | } |
| 40 | a := make([]byte, len(s)+1) |
| 41 | copy(a, s) |
| 42 | return a, nil |
| 43 | } |
| 44 | |
| 45 | // BytePtrFromString returns a pointer to a NUL-terminated array of |
| 46 | // bytes containing the text of s. If s contains a NUL byte at any |
| 47 | // location, it returns (nil, syscall.EINVAL). |
| 48 | func BytePtrFromString(s string) (*byte, error) { |
| 49 | a, err := ByteSliceFromString(s) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | return &a[0], nil |
| 54 | } |
| 55 | |
| 56 | // Single-word zero for use when we need a valid pointer to 0 bytes. |
| 57 | // See mksyscall.pl. |
| 58 | var _zero uintptr |
| 59 | |
| 60 | func (ts *Timespec) Unix() (sec int64, nsec int64) { |
| 61 | return int64(ts.Sec), int64(ts.Nsec) |
| 62 | } |
| 63 | |
| 64 | func (tv *Timeval) Unix() (sec int64, nsec int64) { |
| 65 | return int64(tv.Sec), int64(tv.Usec) * 1000 |
| 66 | } |
| 67 | |
| 68 | func (ts *Timespec) Nano() int64 { |
| 69 | return int64(ts.Sec)*1e9 + int64(ts.Nsec) |
| 70 | } |
| 71 | |
| 72 | func (tv *Timeval) Nano() int64 { |
| 73 | return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 |
| 74 | } |