libc

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 18 Imported by: 10

Documentation

Index

Constants

View Source
const CLOCKS_PER_SEC = 1000000 // us
View Source
const CLOCK_MONOTONIC = 1
View Source
const CLOCK_REALTIME = 0
View Source
const RandMax = math.MaxInt32
View Source
const V1Defined = true
View Source
const WCharSize = int(unsafe.Sizeof(WChar(0)))

Variables

View Source
var (
	Errno int
)

Functions

func AddrAsFunc

func AddrAsFunc(addr uintptr, typ interface{}) interface{}

AddrAsFunc converts a function address to a function value. The caller must type-assert to an expected function type. The function type can be specified as (*func())(nil).

func ArgCopy

func ArgCopy(dst, src *ArgList)

func AsFunc

func AsFunc(p interface{}, typ interface{}) interface{}

AsFunc is a less restrictive version of AddrAsFunc. It accepts a pointer value that may be one of: uintptr, unsafe.Pointer, *T, int, uint.

func AsPtr

func AsPtr(v interface{}) (unsafe.Pointer, error)

func AscTime

func AscTime(tm *TimeInfo) *byte

func Assert

func Assert(cond bool)

func Atof

func Atof(s string) float64

func Atoi

func Atoi(s string) int

func BoolToInt

func BoolToInt(v bool) int32

func BytesN deprecated

func BytesN(p *byte, sz int) []byte

BytesN makes a slice of a given size starting at ptr. It accepts a *byte instead of unsafe pointer as UnsafeBytesN does, which allows to avoid unsafe import.

Deprecated: use unsafe.Slice

func CBytes

func CBytes(b []byte) *byte

CBytes makes a new zero-terminated byte array containing a given byte slice.

func CString

func CString(s string) *byte

CString makes a new zero-terminated byte array containing a given string.

func CStringSlice

func CStringSlice(arr []string) **byte

CStringSlice convers a Go string slice to a zero-terminated array of C string pointers.

func Calloc

func Calloc(num, sz int) unsafe.Pointer

Calloc allocates a region of memory for num elements of size sz.

func ClockGetRes

func ClockGetRes(c Clock, ts *TimeSpec) int32

func ClockGetTime

func ClockGetTime(c Clock, ts *TimeSpec) int32

func ClockSetTime

func ClockSetTime(c Clock, ts *TimeSpec) int32

func ErrCode

func ErrCode(err error) int

ErrCode returns an error code corresponding to a Go error.

func Error

func Error() error

Error returns a Go error value that corresponds to the current Errno.

func Free

func Free(p unsafe.Pointer)

Free marks the memory as freed. May be a nop in Go.

func FuncAddr

func FuncAddr(v interface{}) uintptr

FuncAddr converts a function value to a uintptr.

func FuncAddrUnsafe

func FuncAddrUnsafe(v interface{}) unsafe.Pointer

FuncAddrUnsafe converts a function value to a unsafe.Pointer.

func FuncName

func FuncName() string

func GoBytes

func GoBytes(ptr *byte) []byte

GoBytes makes a Go byte slice from a pointer to a zero-terminated byte array. The slice will point to the same memory as ptr.

func GoBytesS

func GoBytesS(s []byte) []byte

GoBytesS is a Go-friendly analog of GoBytes.

func GoString

func GoString(s *byte) string

GoString makes a Go string from a pointer to a zero-terminated byte array.

func GoStringS

func GoStringS(s []byte) string

GoStringS is a Go-friendly analog of GoString.

func GoWString

func GoWString(s *WChar) string

func IndexBytePtr deprecated

func IndexBytePtr(p *byte, i int) *byte

IndexBytePtr unsafely moves a byte pointer by i bytes. An offset may be negative.

Deprecated: use unsafe.Add

func IndexUnsafePtr deprecated

func IndexUnsafePtr(p unsafe.Pointer, i int) unsafe.Pointer

IndexUnsafePtr unsafely moves a pointer by i bytes. An offset may be negative.

Deprecated: use unsafe.Add

func IsAlnum

func IsAlnum(c rune) bool

func IsAlpha

func IsAlpha(c rune) bool

func LoadAddInt32

func LoadAddInt32(p *int32, v int32) int32

func LoadAndInt32

func LoadAndInt32(p *int32, v int32) int32

func LoadNandInt32

func LoadNandInt32(p *int32, v int32) int32

func LoadOrInt32

func LoadOrInt32(p *int32, v int32) int32

func LoadSubInt32

func LoadSubInt32(p *int32, v int32) int32

func LoadXorInt32

func LoadXorInt32(p *int32, v int32) int32

func Malloc

func Malloc(sz int) unsafe.Pointer

Malloc allocates a region of memory.

func Mbstowcs

func Mbstowcs(a1 *WChar, a2 *byte, a3 uint32) uint32

func MemChr

func MemChr(ptr *byte, ch byte, sz int) *byte

MemChr finds the first occurrence of ch (after conversion to byte as if by byte(ch)) in the initial count characters (each interpreted as byte) of the object pointed to by ptr.

The behavior is undefined if access occurs beyond the end of the array searched. The behavior is undefined if ptr is a null pointer.

func MemCmp

func MemCmp(lhs, rhs unsafe.Pointer, sz int) int

MemCmp compares the first count characters of the objects pointed to by lhs and rhs. The comparison is done lexicographically.

The sign of the result is the sign of the difference between the values of the first pair of bytes (both interpreted as byte) that differ in the objects being compared.

The behavior is undefined if access occurs beyond the end of either object pointed to by lhs and rhs. The behavior is undefined if either lhs or rhs is a null pointer.

func MemCpy

func MemCpy(dst, src unsafe.Pointer, sz int) unsafe.Pointer

MemCpy copies count characters from the object pointed to by src to the object pointed to by dest. Both objects are interpreted as arrays of byte.

The behavior is undefined if access occurs beyond the end of the dest array. If the objects overlap (which is a violation of the restrict contract), the behavior is undefined. The behavior is undefined if either dest or src is a null pointer.

func MemMove

func MemMove(dst, src unsafe.Pointer, sz int) unsafe.Pointer

MemMove copies count characters from the object pointed to by src to the object pointed to by dest. Both objects are interpreted as arrays of byte. The objects may overlap: copying takes place as if the characters were copied to a temporary character array and then the characters were copied from the array to dest.

The behavior is undefined if access occurs beyond the end of the dest array. The behavior is undefined if either dest or src is a null pointer.

func MemSet

func MemSet(p unsafe.Pointer, ch byte, sz int) unsafe.Pointer

MemSet copies the value ch (after conversion to byte as if by byte(ch)) into each of the first count characters of the object pointed to by dest.

The behavior is undefined if access occurs beyond the end of the dest array. The behavior is undefined if dest is a null pointer.

func PointerDiff

func PointerDiff(a, b unsafe.Pointer) int

PointerDiff calculates (a - b).

func Rand

func Rand() int32

func Realloc

func Realloc(buf unsafe.Pointer, sz int) unsafe.Pointer
func Search(key, base unsafe.Pointer, num, size uint32, compar func(a, b unsafe.Pointer) int32) unsafe.Pointer

func SeedRand

func SeedRand(seed uint32)

func SetErr

func SetErr(err error)

SetErr sets the Errno value to a specified Go error equivalent.

func Sort

func Sort(base unsafe.Pointer, num, size uint32, compar func(a, b unsafe.Pointer) int32)

func StrCSpn

func StrCSpn(a, b *byte) int

func StrCaseCmp

func StrCaseCmp(a, b *byte) int

func StrCat

func StrCat(dst, src *byte) *byte

StrCat appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination.

Destination and source shall not overlap.

func StrChr

func StrChr(str *byte, ch byte) *byte

StrChr finds the first occurrence of ch (after conversion to byte as if by byte(ch)) in the null-terminated byte string pointed to by str (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found when searching for '\x00'.

The behavior is undefined if str is not a pointer to a null-terminated byte string.

The return value is a pointer to the found character in str, or null pointer if no such character is found.

func StrCmp

func StrCmp(a, b *byte) int

func StrCpy

func StrCpy(dst, src *byte) *byte

StrCpy copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).

To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source.

func StrCpyGo

func StrCpyGo(dst *byte, src []byte)

StrCpyGo copies a Go slice into a C string pointed by dst. It won't add the null terminator.

func StrCpyGoZero

func StrCpyGoZero(dst *byte, src []byte)

StrCpyGoZero is the same as StrCpyGo, but adds a null terminator.

func StrDup

func StrDup(s *byte) *byte

StrDup copies a null-terminated C string.

func StrError

func StrError(e int) *byte

StrError returns a C string for the current error, if any.

func StrLen

func StrLen(str *byte) int

StrLen returns the length of the given null-terminated byte string, that is, the number of characters in a character array whose first element is pointed to by str up to and not including the first null character.

The behavior is undefined if str is not a pointer to a null-terminated byte string.

func StrLenS

func StrLenS(s []byte) int

StrLenS is a Go-friendly analog of StrLen.

func StrNCaseCmp

func StrNCaseCmp(a, b *byte, sz int) int

func StrNCat

func StrNCat(dst, src *byte, sz int) *byte

StrNCat appends the first num characters of source to destination, plus a terminating null-character.

If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.

func StrNCmp

func StrNCmp(a, b *byte, sz int) int

func StrNCpy

func StrNCpy(dst, src *byte, sz int) *byte

StrNCpy copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it.

No null-character is implicitly appended at the end of destination if source is longer than num. Thus, in this case, destination shall not be considered a null terminated C string (reading it as such would overflow).

Destination and source shall not overlap (see MemMove for a safer alternative when overlapping).

func StrNDup added in v0.3.7

func StrNDup(s *byte, n int) *byte

StrNDup copies a null-terminated C string up to N bytes. Null terminator is added if the string is larger than N.

func StrRChr

func StrRChr(str *byte, ch byte) *byte

StrRChr finds the last occurrence of ch (after conversion to byte as if by byte(ch)) in the null-terminated byte string pointed to by str (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found when searching for '\x00'.

The behavior is undefined if str is not a pointer to a null-terminated byte string.

The return value is a pointer to the found character in str, or null pointer if no such character is found.

func StrSpn

func StrSpn(str, chars *byte) int

StrSpn returns the length of the initial portion of str1 which consists only of characters that are part of str2.

The search does not include the terminating null-characters of either strings, but ends there.

func StrStr

func StrStr(str, substr *byte) *byte

StrStr finds the first occurrence of the null-terminated byte string pointed to by substr in the null-terminated byte string pointed to by str. The terminating null characters are not compared.

The behavior is undefined if either str or substr is not a pointer to a null-terminated byte string.

The return value is a pointer to the first character of the found substring in str, or NULL if such substring is not found. If substr points to an empty string, str is returned.

func StrTok

func StrTok(src, delim *byte) *byte

StrTok is used in a sequence of calls to split str into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.

On a first call, the function expects a C string as argument for str, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of the last token as the new starting location for scanning.

To determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token. The scan also stops if the terminating null character is found.

This end of the token is automatically replaced by a null-character, and the beginning of the token is returned by the function.

Once the terminating null character of str is found in a call to strtok, all subsequent calls to this function (with a null pointer as the first argument) return a null pointer.

The point where the last token was found is kept internally by the function to be used on the next call (particular library implementations are not required to avoid data races).

func ToPointer

func ToPointer(p uintptr) unsafe.Pointer

ToPointer converts a uintptr to unsafe.Pointer.

func ToUintptr

func ToUintptr(p unsafe.Pointer) uintptr

ToUintptr converts a unsafe.Pointer to uintptr.

func Uint16N deprecated

func Uint16N(p *uint16, sz int) []uint16

Uint16N makes a uint16 slice of a given size starting at ptr. It accepts a *uint16 instead of unsafe pointer as UnsafeUint16N does, which allows to avoid unsafe import.

Deprecated: use unsafe.Slice

func Uint32N deprecated

func Uint32N(p *uint32, sz int) []uint32

Uint32N makes a uint32 slice of a given size starting at ptr. It accepts a *uint32 instead of unsafe pointer as UnsafeUint32N does, which allows to avoid unsafe import.

Deprecated: use unsafe.Slice

func UnsafeBytesN deprecated

func UnsafeBytesN(ptr unsafe.Pointer, sz int) []byte

UnsafeBytesN makes a slice of a given size starting at ptr.

Deprecated: use unsafe.Slice

func UnsafeUint16N deprecated

func UnsafeUint16N(ptr unsafe.Pointer, sz int) []uint16

UnsafeUint16N makes a uint16 slice of a given size starting at ptr.

Deprecated: use unsafe.Slice

func UnsafeUint32N deprecated

func UnsafeUint32N(ptr unsafe.Pointer, sz int) []uint32

UnsafeUint32N makes a uint32 slice of a given size starting at ptr.

Deprecated: use unsafe.Slice

func WStrCaseCmp

func WStrCaseCmp(a, b *WChar) int

func WStrCmp

func WStrCmp(a, b *WChar) int

func WStrLen

func WStrLen(str *WChar) uint64

func WStrtol

func WStrtol(s *WChar, end **WChar, base int) int

func Wctob

func Wctob(wc WChar) int64

Types

type ArgList

type ArgList struct {
	// contains filtered or unexported fields
}

func (*ArgList) Arg

func (va *ArgList) Arg() interface{}

func (*ArgList) ArgUintptr

func (va *ArgList) ArgUintptr() uintptr

func (*ArgList) Args

func (va *ArgList) Args() []interface{}

func (*ArgList) End

func (va *ArgList) End()

func (*ArgList) Start

func (va *ArgList) Start(typ interface{}, rest []interface{})

type Clock

type Clock int32

func ClockTicks

func ClockTicks() Clock

type ClockID

type ClockID uint32

type JumpBuf

type JumpBuf struct {
	// contains filtered or unexported fields
}

func (*JumpBuf) LongJump

func (b *JumpBuf) LongJump(val int)

func (*JumpBuf) SetJump

func (b *JumpBuf) SetJump() int

type Time

type Time int32

func GetTime

func GetTime(dst *Time) Time

func MakeTime

func MakeTime(src *TimeInfo) Time

func (Time) GoTime

func (t Time) GoTime() time.Time

type TimeInfo

type TimeInfo struct {
	Sec      int32
	Min      int32
	Hour     int32
	Day      int32
	Month    int32
	Year     int32
	WeekDay  int32
	YearDay  int32
	IsDst    int32
	Timezone unsafe.Pointer
	GMTOffs  int32
}

func LocalTime

func LocalTime(src *Time) *TimeInfo

func (*TimeInfo) GoTime

func (tm *TimeInfo) GoTime() time.Time

type TimeSpec

type TimeSpec struct {
	Sec  Time
	NSec int64
}

type TimeVal

type TimeVal struct {
	Sec  Time
	USec int64
}

type Timer

type Timer uint32

type WChar

type WChar = uint16

func CWString

func CWString(s string) *WChar

CWString makes a new zero-terminated wide char array containing a given string.

func GoWSlice

func GoWSlice(ptr *WChar) []WChar

func IndexWCharPtr deprecated

func IndexWCharPtr(p *WChar, i int) *WChar

IndexWCharPtr unsafely moves a wide char pointer by i elements. An offset may be negative.

Deprecated: use unsafe.Add

func UnsafeWCharN deprecated

func UnsafeWCharN(ptr unsafe.Pointer, sz uint64) []WChar

UnsafeWCharN makes a slice of a given size starting at ptr.

Deprecated: use unsafe.Slice

func WCharN deprecated

func WCharN(p *WChar, sz uint64) []WChar

WCharN makes a slice of a given size starting at ptr. It accepts a *WChar instead of unsafe pointer as UnsafeWCharN does, which allows to avoid unsafe import.

Deprecated: use unsafe.Slice

func WStrCat

func WStrCat(dst, src *WChar) *WChar

func WStrChr

func WStrChr(str *WChar, ch int64) *WChar

func WStrCpy

func WStrCpy(dst, src *WChar) *WChar

func WStrNCpy

func WStrNCpy(dst, src *WChar, sz uint32) *WChar

func WStrTok

func WStrTok(src, delim *WChar) *WChar

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL