...
Run Format

Source file src/syscall/syscall.go

Documentation: syscall

     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  // NOTE: This package is locked down. Code outside the standard
    22  // Go repository should be migrated to use the corresponding
    23  // package in the golang.org/x/sys repository. That is also where updates
    24  // required by new systems or versions should be applied.
    25  // Signal, Errno and SysProcAttr are not yet available in
    26  // golang.org/x/sys and must still be referenced from the
    27  // syscall package. See https://golang.org/s/go1.4-syscall
    28  // for more information.
    29  //
    30  package syscall
    31  
    32  //go:generate go run mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
    33  
    34  // StringByteSlice converts a string to a NUL-terminated []byte,
    35  // If s contains a NUL byte this function panics instead of
    36  // returning an error.
    37  //
    38  // Deprecated: Use ByteSliceFromString instead.
    39  func StringByteSlice(s string) []byte {
    40  	a, err := ByteSliceFromString(s)
    41  	if err != nil {
    42  		panic("syscall: string with NUL passed to StringByteSlice")
    43  	}
    44  	return a
    45  }
    46  
    47  // ByteSliceFromString returns a NUL-terminated slice of bytes
    48  // containing the text of s. If s contains a NUL byte at any
    49  // location, it returns (nil, EINVAL).
    50  func ByteSliceFromString(s string) ([]byte, error) {
    51  	for i := 0; i < len(s); i++ {
    52  		if s[i] == 0 {
    53  			return nil, EINVAL
    54  		}
    55  	}
    56  	a := make([]byte, len(s)+1)
    57  	copy(a, s)
    58  	return a, nil
    59  }
    60  
    61  // StringBytePtr returns a pointer to a NUL-terminated array of bytes.
    62  // If s contains a NUL byte this function panics instead of returning
    63  // an error.
    64  //
    65  // Deprecated: Use BytePtrFromString instead.
    66  func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
    67  
    68  // BytePtrFromString returns a pointer to a NUL-terminated array of
    69  // bytes containing the text of s. If s contains a NUL byte at any
    70  // location, it returns (nil, EINVAL).
    71  func BytePtrFromString(s string) (*byte, error) {
    72  	a, err := ByteSliceFromString(s)
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  	return &a[0], nil
    77  }
    78  
    79  // Single-word zero for use when we need a valid pointer to 0 bytes.
    80  // See mksyscall.pl.
    81  var _zero uintptr
    82  
    83  // Unix returns ts as the number of seconds and nanoseconds elapsed since the
    84  // Unix epoch.
    85  func (ts *Timespec) Unix() (sec int64, nsec int64) {
    86  	return int64(ts.Sec), int64(ts.Nsec)
    87  }
    88  
    89  // Unix returns tv as the number of seconds and nanoseconds elapsed since the
    90  // Unix epoch.
    91  func (tv *Timeval) Unix() (sec int64, nsec int64) {
    92  	return int64(tv.Sec), int64(tv.Usec) * 1000
    93  }
    94  
    95  // Nano returns ts as the number of nanoseconds elapsed since the Unix epoch.
    96  func (ts *Timespec) Nano() int64 {
    97  	return int64(ts.Sec)*1e9 + int64(ts.Nsec)
    98  }
    99  
   100  // Nano returns tv as the number of nanoseconds elapsed since the Unix epoch.
   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)
   109  

View as plain text