types

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: GPL-3.0 Imports: 20 Imported by: 7

Documentation

Index

Constants

View Source
const (
	TS_TO_NANO_TS = 1000000000 // second to nano-second

	SYS_BUFFER_SIZE = 8192

	DEFAULT_FOLDER_CREATE_PERM = 0o755
	DEFAULT_FILE_CREATE_PERM   = 0o644
)
View Source
const INT32_SZ = unsafe.Sizeof(int32(0))
View Source
const PID_SZ = unsafe.Sizeof(Pid_t(0))
View Source
const TIME4_SZ = unsafe.Sizeof(Time4(0))

XXX check whether INT32_SZ should be TIME4_SZ

View Source
const UINT32_SZ = unsafe.Sizeof(uint32(0))
View Source
const UINT8_SZ = unsafe.Sizeof(uint8(0))

Variables

View Source
var (
	TIME_LOCATION = "Asia/Taipei"

	IS_ALLOW_CROSSDOMAIN = true

	DEFAULT_PID_MAX = Pid_t(10000000)

	// big5
	BIG5_TO_UTF8 = "types/uao250-b2u.big5.txt"
	UTF8_TO_BIG5 = "types/uao250-u2b.big5.txt"
	AMBCJK       = "types/ambcjk.big5.txt"
)
View Source
var (
	ErrInvalidIni    = errors.New("invalid ini")
	ErrBytesTooLarge = errors.New("bytes too large")
	ErrNilReader     = errors.New("nil reader")

	ErrNotImplemented = errors.New("not implemented")

	ErrInvalidTimeLocale = errors.New("invalid time locale")

	ErrInvalidFile = errors.New("invalid file")

	ErrInvalidSize = errors.New("invalid size")
)
View Source
var (
	ZERO_TIME       = time.Unix(int64(0), 0)
	ZERO_LOCAL_TIME = ZERO_TIME.In(TIMEZONE)
	ZERO_TIME4      = Time4(0)
)
View Source
var (
	VERSION     string
	GIT_VERSION string
)
View Source
var MILLI_TS_TO_NANO_TS int64 = 1000000

Functions

func Big5ToUtf8

func Big5ToUtf8(big5 []byte) (utf8 string)

func BinRead

func BinRead(file io.ReadSeeker, v interface{}, theSize uintptr) error

BinRead

Read the file with identified size, the first bytes are fit in v. Assuming that the size of v is <= theSize. XXX not sure what to do if v > theSize.

func BinWrite

func BinWrite(file io.Writer, v interface{}, theSize uintptr) error

BinWrite

Write the file with identified size, the first bytes are with v. Assuming that the size of v is <= theSize. XXX not sure what to do if v > theSize.

func BinaryRead added in v0.15.1

func BinaryRead(reader io.ReadSeeker, order binary.ByteOrder, data interface{}) (err error)

func BinaryWrite added in v0.15.1

func BinaryWrite(writer io.Writer, order binary.ByteOrder, data interface{}) (err error)

func CcharTolower

func CcharTolower(ch byte) byte

func CcharToupper added in v0.2.3

func CcharToupper(ch byte) byte

func CopyDirToDir

func CopyDirToDir(src string, dst string) (err error)

func CopyFile

func CopyFile(src string, dst string) (err error)

func CopyFileToDir

func CopyFileToDir(src string, dst string) (err error)

func CopyFileToFile

func CopyFileToFile(src string, dst string) (err error)

func CstrCaseHasPrefix added in v0.10.0

func CstrCaseHasPrefix(cstr Cstr, substr Cstr) bool

func CstrToBytes

func CstrToBytes(cstr Cstr) []byte

CstrToBytes

Only the bytes until \0. See tests for more examples.

Params

cstr

Return

[]byte: bytes

func CstrToString

func CstrToString(cstr Cstr) string

CstrToString

Only the bytes until \0 when converting to string. See tests for more examples.

Params

cstr

Return

string: string

func Cstrcasecmp

func Cstrcasecmp(cstr1 Cstr, cstr2 Cstr) int

func Cstrcasestr

func Cstrcasestr(cstr Cstr, substr Cstr) int

func Cstrcmp

func Cstrcmp(cstr1 Cstr, cstr2 Cstr) int

Cstrcmp The reason that we don't directly do C.strcmp is because cstr1 or cstr2 may not have \x00 in the end.

func Cstrlen

func Cstrlen(cstr Cstr) int

func Cstrstr

func Cstrstr(cstr Cstr, substr Cstr) int

func DashD added in v0.14.4

func DashD(filename string) (isDir bool)

func DashF added in v0.14.4

func DashF(filename string) (isExists bool, err error)

func DashS added in v0.12.0

func DashS(filename string) (theSize int64)

func ErrRecover added in v0.15.1

func ErrRecover(err interface{}) error

func GetCurrentMilliTS

func GetCurrentMilliTS() int64

func GetRandom

func GetRandom() string

func InitConfig

func InitConfig() error

func IsDir

func IsDir(path string) bool

IsDir

dashd in cmsys/file.c

func IsRegularFile

func IsRegularFile(filename string) bool

func Isalnum

func Isalnum(c byte) bool

func Isalpha

func Isalpha(c byte) bool

func Isascii added in v0.18.0

func Isascii(c byte) bool

func Isnumber

func Isnumber(c byte) bool

func Kill added in v0.5.0

func Kill(pid Pid_t, sig os.Signal) (err error)

func Mkdir

func Mkdir(path string) error

func MkdirAll added in v0.11.1

func MkdirAll(path string) error

func OpenCreate added in v0.12.0

func OpenCreate(filename string, flags int) (file *os.File, err error)

func ReadFile

func ReadFile(filename string) ([]byte, error)

func ReadLine added in v0.2.3

func ReadLine(reader *bufio.Reader) ([]byte, error)

ReadLine

To avoid confusion, use only []byte is nil or not to know whether it's the end of file.

func Rename

func Rename(src string, dst string) (err error)

Rename

Force rename src to dst by recursively-deleting old dst.

func SetIsTest added in v0.12.0

func SetIsTest(name string)
func Symlink(src string, dst string) (err error)

func TrimDBCS added in v0.16.0

func TrimDBCS(theCstr Cstr) (theBytes []byte)
func Unlink(filename string) (err error)

func UnsetIsTest added in v0.12.0

func UnsetIsTest(name string)

func Utf8ToBig5

func Utf8ToBig5(utf8 string) (big5 []byte)

Types

type Cstr

type Cstr []byte

Cstr

[]byte with C String property in that \0 is considered as the end of the bytes/string. It is used to convert from fixed-length bytes to string or []byte with no \0.

Naming Cstr instead of CString is to avoid confusion with C.CString (C.CString is from string, and should be compatible with string, not with []byte) (We also have str(len/cpy/cmp) functions in C)

See tests for more examples of how to use fixed-bytes with Cstr to get no-\0 string / []byte

func CstrTokenR added in v0.8.3

func CstrTokenR(cstr Cstr, sep []byte) (first Cstr, theRest []byte)

func CstrTolower

func CstrTolower(cstr Cstr) Cstr

func CstrToupper added in v0.2.3

func CstrToupper(cstr Cstr) Cstr

type DBCU

type DBCU struct {
	Color  uint8 // color for the 1st byte. 8bit color in terminal.
	Color2 uint8 // color for the 2nd byte.
	Rune   rune  // unicode
}

type InAddr_t

type InAddr_t uint32

func InetAddr added in v0.5.0

func InetAddr(ipStr string) InAddr_t

InetAddr

if unable to parse: return 0 (0.0.0.0)

type Key_t

type Key_t int

type Pid_t

type Pid_t int32

type Size_t

type Size_t uint32

type Time4

type Time4 int32

func DashT added in v0.12.0

func DashT(filename string) (t Time4)

func NowTS

func NowTS() Time4

func TimeToTime4 added in v0.8.1

func TimeToTime4(t time.Time) Time4

func (Time4) Cdate

func (t Time4) Cdate() string

Cdate

Print date-time in string. 23+1 bytes, "01/31/2007 00:00:00 Mon\0"

func (Time4) CdateMd

func (t Time4) CdateMd() string

CdateMd

Print month/day in string 5+1 bytes, "01/31\0"

func (Time4) CdateMdHM

func (t Time4) CdateMdHM() string

CdateMdHM

Print month/day hour:minute in string 11+1 bytes, "01/31 10:01\0"

func (Time4) CdateMdHMS

func (t Time4) CdateMdHMS() string

CdateMdHMS

Print month/day hour:minute:second in string 13+1 bytes, "01/31 10:01:01\0"

func (Time4) Cdatedate

func (t Time4) Cdatedate() string

Cdatedate

Print date in string. 10+1 bytes, "01/31/2007\0"

func (Time4) Cdatelite

func (t Time4) Cdatelite() string

Cdatelite

Light-print date-time in string. 19+1 bytes, "01/31/2007 00:00:00\0"

func (Time4) Cdatemd added in v0.12.0

func (t Time4) Cdatemd() (str string)

Cdatemd

Print month/day in string 5+1 bytes, " 1/31\0"

func (Time4) Ctime added in v0.12.0

func (t Time4) Ctime() string

Ctime Sun Feb 14 13:33:27 2021

func (Time4) ToLocal

func (t Time4) ToLocal() time.Time

ToLocal

Instead of using Local, we specify TIME_LOCATION to avoid the confusion. (also good for tests)

func (Time4) ToUtc

func (t Time4) ToUtc() time.Time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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