src/pkg/syscall/syscall.go - The Go Programming Language

Golang

Source file src/pkg/syscall/syscall.go

     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.
     7	// Its primary use is inside other packages that provide a more portable
     8	// interface to the system, such as "os", "time" and "net".  Use those
     9	// packages rather than this one if you can.
    10	// For details of the functions and data types in this package consult
    11	// the manuals for the appropriate operating system.
    12	// These calls return err == nil to indicate success; otherwise
    13	// err is an operating system error describing the failure.
    14	// On most systems, that error has type syscall.Errno.
    15	package syscall
    16	
    17	// StringByteSlice returns a NUL-terminated slice of bytes
    18	// containing the text of s.
    19	func StringByteSlice(s string) []byte {
    20		a := make([]byte, len(s)+1)
    21		copy(a, s)
    22		return a
    23	}
    24	
    25	// StringBytePtr returns a pointer to a NUL-terminated array of bytes
    26	// containing the text of s.
    27	func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
    28	
    29	// Single-word zero for use when we need a valid pointer to 0 bytes.
    30	// See mksyscall.pl.
    31	var _zero uintptr
    32	
    33	func (ts *Timespec) Unix() (sec int64, nsec int64) {
    34		return int64(ts.Sec), int64(ts.Nsec)
    35	}
    36	
    37	func (tv *Timeval) Unix() (sec int64, nsec int64) {
    38		return int64(tv.Sec), int64(tv.Usec) * 1000
    39	}
    40	
    41	func (ts *Timespec) Nano() int64 {
    42		return int64(ts.Sec)*1e9 + int64(ts.Nsec)
    43	}
    44	
    45	func (tv *Timeval) Nano() int64 {
    46		return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
    47	}