Retro68/gcc/libgo/go/syscall/syscall.go

112 lines
3.8 KiB
Go
Raw Normal View History

2012-03-27 23:13:14 +00:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package syscall contains an interface to the low-level operating system
// primitives. The details vary depending on the underlying system, and
2014-09-21 17:33:12 +00:00
// by default, godoc will display the syscall documentation for the current
// system. If you want godoc to display syscall documentation for another
// system, set $GOOS and $GOARCH to the desired system. For example, if
2014-09-21 17:33:12 +00:00
// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
// to freebsd and $GOARCH to arm.
// The primary use of syscall is inside other packages that provide a more
// portable interface to the system, such as "os", "time" and "net". Use
// those packages rather than this one if you can.
2012-03-27 23:13:14 +00:00
// For details of the functions and data types in this package consult
// the manuals for the appropriate operating system.
// These calls return err == nil to indicate success; otherwise
// err is an operating system error describing the failure.
// On most systems, that error has type syscall.Errno.
2015-08-28 15:33:40 +00:00
//
2019-06-02 15:48:37 +00:00
// Deprecated: this package is locked down. Callers should use the
// corresponding package in the golang.org/x/sys repository instead.
// That is also where updates required by new systems or versions
// should be applied. See https://golang.org/s/go1.4-syscall for more
// information.
2015-08-28 15:33:40 +00:00
//
2012-03-27 23:13:14 +00:00
package syscall
import "unsafe"
//go:generate go run mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
2017-04-10 11:32:00 +00:00
// StringByteSlice converts a string to a NUL-terminated []byte,
2014-09-21 17:33:12 +00:00
// If s contains a NUL byte this function panics instead of
// returning an error.
2017-04-10 11:32:00 +00:00
//
// Deprecated: Use ByteSliceFromString instead.
2012-03-27 23:13:14 +00:00
func StringByteSlice(s string) []byte {
2014-09-21 17:33:12 +00:00
a, err := ByteSliceFromString(s)
if err != nil {
panic("syscall: string with NUL passed to StringByteSlice")
}
return a
}
// ByteSliceFromString returns a NUL-terminated slice of bytes
// containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
func ByteSliceFromString(s string) ([]byte, error) {
for i := 0; i < len(s); i++ {
if s[i] == 0 {
return nil, EINVAL
}
}
2012-03-27 23:13:14 +00:00
a := make([]byte, len(s)+1)
copy(a, s)
2014-09-21 17:33:12 +00:00
return a, nil
2012-03-27 23:13:14 +00:00
}
2017-04-10 11:32:00 +00:00
// StringBytePtr returns a pointer to a NUL-terminated array of bytes.
// If s contains a NUL byte this function panics instead of returning
// an error.
//
// Deprecated: Use BytePtrFromString instead.
2012-03-27 23:13:14 +00:00
func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
2014-09-21 17:33:12 +00:00
// BytePtrFromString returns a pointer to a NUL-terminated array of
// bytes containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
func BytePtrFromString(s string) (*byte, error) {
a, err := ByteSliceFromString(s)
if err != nil {
return nil, err
}
return &a[0], nil
}
2012-03-27 23:13:14 +00:00
// Single-word zero for use when we need a valid pointer to 0 bytes.
// See mksyscall.pl.
var _zero uintptr
var dummy *byte
const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
2018-12-28 15:30:48 +00:00
// Unix returns ts as the number of seconds and nanoseconds elapsed since the
// Unix epoch.
2012-03-27 23:13:14 +00:00
func (ts *Timespec) Unix() (sec int64, nsec int64) {
return int64(ts.Sec), int64(ts.Nsec)
}
2018-12-28 15:30:48 +00:00
// Unix returns tv as the number of seconds and nanoseconds elapsed since the
// Unix epoch.
2012-03-27 23:13:14 +00:00
func (tv *Timeval) Unix() (sec int64, nsec int64) {
return int64(tv.Sec), int64(tv.Usec) * 1000
}
2018-12-28 15:30:48 +00:00
// Nano returns ts as the number of nanoseconds elapsed since the Unix epoch.
2012-03-27 23:13:14 +00:00
func (ts *Timespec) Nano() int64 {
return int64(ts.Sec)*1e9 + int64(ts.Nsec)
}
2018-12-28 15:30:48 +00:00
// Nano returns tv as the number of nanoseconds elapsed since the Unix epoch.
2012-03-27 23:13:14 +00:00
func (tv *Timeval) Nano() int64 {
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
}
2015-08-28 15:33:40 +00:00
2018-12-28 15:30:48 +00:00
// Getpagesize and Exit are provided by the runtime.
func Getpagesize() int
2018-12-28 15:30:48 +00:00
func Exit(code int)