XU XUv0.8.8
中文

API

#os

import: #os

counts: 73 fns, 16 methods, 5 types, 9 consts, 0 ifaces

Process, files, environment. Hosted File: open/create/read/write/close. getwd returns empty on failure.

args

XuAPI
pub fn args() []string

Purpose

sys_args is the private builtin spelling. Calling args from this module would resolve to the public wrapper below and recurse.

Parameters

none

Returns

[]string — slice result

argv

XuAPI
pub fn argv() []string

Purpose

argv is retained as the compatibility spelling used by older Xu programs.

Parameters

none

Returns

[]string — slice result

read

XuAPI
pub fn read(path string) string

Purpose

read reads the file named by path and returns the contents. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

string — result string

write

XuAPI
pub fn write(path string, data string) int

Purpose

write writes data to the named file, creating it if necessary. Throws on failure.

Parameters

path string
filesystem path (string)
data string
data (string)

Returns

int — bytes written

struct File

XuAPI
pub struct File {

}

Purpose

Streaming file owner. Non-Copy via its compiler-managed drop hook.

Parameters

none

const o_rdonly

XuAPI
pub const o_rdonly = 0

Purpose

Public constant `o_rdonly`. Value `0`.

Parameters

none

const o_create

XuAPI
pub const o_create = 1

Purpose

Public constant `o_create`. Value `1`.

Parameters

none

const o_append

XuAPI
pub const o_append = 2

Purpose

Public constant `o_append`. Value `2`.

Parameters

none

const o_excl

XuAPI
pub const o_excl = 3

Purpose

Public constant `o_excl`. Value `3`.

Parameters

none

const o_lock

XuAPI
pub const o_lock = 4

Purpose

Public constant `o_lock`. Value `4`.

Parameters

none

const o_lock_existing

XuAPI
pub const o_lock_existing = 5

Purpose

Public constant `o_lock_existing`. Value `5`.

Parameters

none

open_lock

XuAPI
pub fn open_lock(path string, existing bool) File

Purpose

Exclusive nonblocking process lock. Closing File or process termination releases it. The stable lock file must never be unlinked while in use. o_lock creates without truncating; o_lock_existing opens read-only. Throws on failure.

Parameters

path string
filesystem path (string)
existing bool
existing (bool)

Returns

File — a value of this type

open

XuAPI
pub fn open(path string) File

Purpose

Open. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

File — a value of this type

create

XuAPI
pub fn create(path string) File

Purpose

Create. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

File — a value of this type

open_append

XuAPI
pub fn open_append(path string) File

Purpose

Open append. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

File — a value of this type

create_excl

XuAPI
pub fn create_excl(path string) File

Purpose

Create excl. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

File — a value of this type

(&File) read

XuAPI
pub fn (f &File) read(max int) string

Purpose

Method on `&File`: read up to max bytes. Throws on failure.

Parameters

f &File
receiver &File (borrow)
max int
maximum (int)

Returns

string — result string

(&File) write

XuAPI
pub fn (f &File) write(data string) int

Purpose

Method on `&File`: write data and return the byte count. Throws on failure.

Parameters

f &File
receiver &File (borrow)
data string
data (string)

Returns

int — bytes written

(&mut File) close

XuAPI
pub fn (f &mut File) close() int

Purpose

Method on `&mut File`: close the resource. Throws on failure.

Parameters

f &mut File
receiver &mut File (exclusive borrow)

Returns

int — a value of this type

const seek_set

XuAPI
pub const seek_set = 0

Purpose

Public constant `seek_set`. Value `0`.

Parameters

none

const seek_cur

XuAPI
pub const seek_cur = 1

Purpose

Public constant `seek_cur`. Value `1`.

Parameters

none

const seek_end

XuAPI
pub const seek_end = 2

Purpose

Public constant `seek_end`. Value `2`.

Parameters

none

(&File) seek

XuAPI
pub fn (f &File) seek(offset int, whence int) int

Purpose

Method on `&File`: move the read position. whence 0/1/2 = absolute / relative / from end. Throws on failure.

Parameters

f &File
receiver &File (borrow)
offset int
offset (int)
whence int
seek base: 0 start / 1 current / 2 end (int)

Returns

int — a value of this type

struct Pipe

XuAPI
pub struct Pipe {
    pub r File
    pub w File
}

Purpose

Public struct `Pipe`.

Parameters

r File
rune (Unicode code point)
w File
writer or width

pipe

XuAPI
pub fn pipe() Pipe

Purpose

pipe; returns Pipe. Throws on failure.

Parameters

none

Returns

Pipe — a value of this type

read_dir

XuAPI
pub fn read_dir(path string) string

Purpose

sys_read_dir avoids the same-name wrapper shadowing the private builtin. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

string — result string

listdir

XuAPI
pub fn listdir(path string) string

Purpose

listdir is retained as a compatibility spelling. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

string — result string

getpid

XuAPI
pub fn getpid() int

Purpose

===== System information =====

Parameters

none

Returns

int — a value of this type

getppid

XuAPI
pub fn getppid() int

Purpose

getppid; returns int.

Parameters

none

Returns

int — a value of this type

getuid

XuAPI
pub fn getuid() int

Purpose

getuid; returns int.

Parameters

none

Returns

int — a value of this type

getgid

XuAPI
pub fn getgid() int

Purpose

getgid; returns int.

Parameters

none

Returns

int — a value of this type

geteuid

XuAPI
pub fn geteuid() int

Purpose

geteuid; returns int.

Parameters

none

Returns

int — a value of this type

getegid

XuAPI
pub fn getegid() int

Purpose

getegid; returns int.

Parameters

none

Returns

int — a value of this type

getpagesize

XuAPI
pub fn getpagesize() int

Purpose

getpagesize; returns int.

Parameters

none

Returns

int — a value of this type

hostname

XuAPI
pub fn hostname() string

Purpose

hostname; returns string.

Parameters

none

Returns

string — result string

getwd

XuAPI
pub fn getwd() string

Purpose

getwd returns a rooted path name corresponding to the current directory.

Parameters

none

Returns

string — result string

getenv

XuAPI
pub fn getenv(name string) string

Purpose

getenv retrieves the value of the environment variable named by the key.

Parameters

name string
name (string)

Returns

string — result string

struct EnvVal

XuAPI
pub struct EnvVal {
    pub value string
    pub found bool
}

Purpose

EnvVal is os.LookupEnv's two results: found is false when unset (empty value with found true is a defined empty string).

Parameters

value string
field (string)
found bool
field (bool)

lookup_env

XuAPI
pub fn lookup_env(name string) EnvVal

Purpose

Lookup env.

Parameters

name string
name (string)

Returns

EnvVal — a value of this type

environ

XuAPI
pub fn environ() []string

Purpose

environ; returns []string.

Parameters

none

Returns

[]string — slice result

temp_dir

XuAPI
pub fn temp_dir() string

Purpose

Temp directory.

Parameters

none

Returns

string — result string

home_dir

XuAPI
pub fn home_dir() string

Purpose

Home directory.

Parameters

none

Returns

string — result string

user_home_dir

XuAPI
pub fn user_home_dir() string

Purpose

User home directory. Throws on failure.

Parameters

none

Returns

string — result string

path_separator

XuAPI
pub fn path_separator() int

Purpose

Path separator.

Parameters

none

Returns

int — a value of this type

is_path_separator

XuAPI
pub fn is_path_separator(c int) bool

Purpose

Whether it is path separator.

Parameters

c int
byte or character code (int)

Returns

bool — true or false

path_list_separator

XuAPI
pub fn path_list_separator() int

Purpose

path_list_separator is os.PathListSeparator: ';' on Windows, ':' elsewhere.

Parameters

none

Returns

int — a value of this type

dev_null

XuAPI
pub fn dev_null() string

Purpose

dev_null is os.DevNull: "NUL" on Windows, "/dev/null" elsewhere.

Parameters

none

Returns

string — result string

user_cache_dir

XuAPI
pub fn user_cache_dir() string

Purpose

User cache directory. Throws on failure.

Parameters

none

Returns

string — result string

user_config_dir

XuAPI
pub fn user_config_dir() string

Purpose

User config directory. Throws on failure.

Parameters

none

Returns

string — result string

stat

XuAPI
pub fn stat(path string) FileInfo

Purpose

===== Filesystem ops ===== Throws on failure.

Parameters

path string
filesystem path (string)

Returns

FileInfo — a value of this type

mkdir

XuAPI
pub fn mkdir(path string) int

Purpose

Create a directory. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

int — a value of this type

rename

XuAPI
pub fn rename(old string, new string) int

Purpose

Rename. Throws on failure.

Parameters

old string
old value / piece to replace (string)
new string
new value / replacement (string)

Returns

int — a value of this type

remove

XuAPI
pub fn remove(path string) int

Purpose

Remove. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

int — a value of this type

chmod

XuAPI
pub fn chmod(path string, mode int) int

Purpose

chmod; returns int. Throws on failure.

Parameters

path string
filesystem path (string)
mode int
mode (int)

Returns

int — a value of this type

chdir

XuAPI
pub fn chdir(path string) int

Purpose

chdir; returns int. Throws on failure.

Parameters

path string
filesystem path (string)

Returns

int — a value of this type

is_dir

XuAPI
pub fn is_dir(path string) bool

Purpose

Whether it is a directory.

Parameters

path string
filesystem path (string)

Returns

bool — true or false

is_not_exist

XuAPI
pub fn is_not_exist(msg string) bool

Purpose

Whether it is not exist.

Parameters

msg string
message (string)

Returns

bool — true or false

is_exist

XuAPI
pub fn is_exist(msg string) bool

Purpose

Whether it is exist.

Parameters

msg string
message (string)

Returns

bool — true or false

is_permission

XuAPI
pub fn is_permission(msg string) bool

Purpose

Whether it is permission.

Parameters

msg string
message (string)

Returns

bool — true or false

is_timeout

XuAPI
pub fn is_timeout(msg string) bool

Purpose

Whether it is timeout.

Parameters

msg string
message (string)

Returns

bool — true or false

struct DirEntry

XuAPI
pub struct DirEntry {
    pub name string
    pub is_dir bool
}

Purpose

Public struct `DirEntry`.

Parameters

name string
name
is_dir bool
field (bool)

entries

XuAPI
pub fn entries(path0 string) []DirEntry

Purpose

entries; returns []DirEntry. Throws on failure.

Parameters

path0 string
path0 (string)

Returns

[]DirEntry — slice result

mkdir_all

XuAPI
pub fn mkdir_all(path0 string) int

Purpose

Mkdir all. Throws on failure.

Parameters

path0 string
path0 (string)

Returns

int — a value of this type

mkdir_temp

XuAPI
pub fn mkdir_temp(dir string, pattern string) string

Purpose

Mkdir temp. Throws on failure.

Parameters

dir string
directory (string)
pattern string
pattern (string)

Returns

string — result string

create_temp

XuAPI
pub fn create_temp(dir string, pattern string) string

Purpose

Create temp. Throws on failure.

Parameters

dir string
directory (string)
pattern string
pattern (string)

Returns

string — result string

remove_all

XuAPI
pub fn remove_all(path0 string) int

Purpose

Remove all.

Parameters

path0 string
path0 (string)

Returns

int — a value of this type

expand_env

XuAPI
pub fn expand_env(s &string) string

Purpose

Expand env.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)

Returns

string — result string

closed_file

XuAPI
pub fn closed_file() File

Purpose

A closed owner for aggregate initialization; no resource is acquired.

Parameters

none

Returns

File — a value of this type

(&mut File) take

XuAPI
pub fn (f &mut File) take() File

Purpose

Transfer a field-owned File without cloning or moving through a borrow. Throws on failure.

Parameters

f &mut File
receiver &mut File (exclusive borrow)

Returns

File — a value of this type

(&mut File) release_descriptor

XuAPI
pub fn (f &mut File) release_descriptor() int

Purpose

Explicit ownership handoff to a raw platform adapter. The adapter must release the returned descriptor exactly once; this owner becomes closed. Throws on failure.

Parameters

f &mut File
receiver &mut File (exclusive borrow)

Returns

int — a value of this type

(&File) descriptor

XuAPI
pub fn (f &File) descriptor() int

Purpose

Borrowed raw descriptor for platform adapters. It does not transfer ownership callers must not close it or manufacture another owner from it. Throws on failure.

Parameters

f &File
receiver &File (borrow)

Returns

int — a value of this type

struct DirFS

XuAPI
pub struct DirFS {
    pub dir string
}

Purpose

`os.DirFS`: a rooted tree that implements the io/fs.FS method set (Open / Stat / ReadFile / ReadDir / Sub). os imports io/fs; DirFS is `fs.FS` via interfaces. Xu: no interface values, so this concrete type lives here; io/fs helpers take `&os.DirFS`. This package does not import io/fs (no cycle).

Parameters

dir string
directory

dir_fs

XuAPI
pub fn dir_fs(dir string) DirFS

Purpose

Directory fs.

Parameters

dir string
directory (string)

Returns

DirFS — a value of this type

(&DirFS) open

XuAPI
pub fn (d &DirFS) open(name string) File

Purpose

Method on `&DirFS`: open. Throws on failure.

Parameters

d &DirFS
receiver &DirFS (borrow)
name string
name (string)

Returns

File — a value of this type

(&DirFS) stat

XuAPI
pub fn (d &DirFS) stat(name string) FileInfo

Purpose

Method on `&DirFS`: read metadata. Throws on failure.

Parameters

d &DirFS
receiver &DirFS (borrow)
name string
name (string)

Returns

FileInfo — a value of this type

(&DirFS) read_dir

XuAPI
pub fn (d &DirFS) read_dir(name string) []DirEntry

Purpose

Method on `&DirFS`: read directory. Throws on failure.

Parameters

d &DirFS
receiver &DirFS (borrow)
name string
name (string)

Returns

[]DirEntry — slice result

(&DirFS) read_file

XuAPI
pub fn (d &DirFS) read_file(name string) string

Purpose

Method on `&DirFS`: read file. Throws on failure.

Parameters

d &DirFS
receiver &DirFS (borrow)
name string
name (string)

Returns

string — result string

(&DirFS) sub

XuAPI
pub fn (d &DirFS) sub(name string) DirFS

Purpose

Method on `&DirFS`: subtract. Throws on failure.

Parameters

d &DirFS
receiver &DirFS (borrow)
name string
name (string)

Returns

DirFS — a value of this type

(&File) read_result

XuAPI
pub fn (f &File) read_result(n int) io.ReadResult

Purpose

Method on `&File`: read result.

Parameters

f &File
receiver &File (borrow)
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

(&File) write_result

XuAPI
pub fn (f &File) write_result(data string) io.WriteResult

Purpose

Method on `&File`: write result.

Parameters

f &File
receiver &File (borrow)
data string
data (string)

Returns

io.WriteResult — a value of this type

socket

XuAPI
pub fn socket(domain int, typ int, proto int) int

Purpose

socket; returns int. Throws on failure.

Parameters

domain int
domain (int)
typ int
typ (int)
proto int
proto (int)

Returns

int — a value of this type

bind4

XuAPI
pub fn bind4(fd int, a int, b int, c int, d int, port int) int

Purpose

bind4; returns int. Throws on failure.

Parameters

fd int
file descriptor (int)
a int
value (int)
b int
b (int)
c int
byte or character code (int)
d int
d (int)
port int
port (int)

Returns

int — a value of this type

connect4

XuAPI
pub fn connect4(fd int, a int, b int, c int, d int, port int) int

Purpose

connect4; returns int. Throws on failure.

Parameters

fd int
file descriptor (int)
a int
value (int)
b int
b (int)
c int
byte or character code (int)
d int
d (int)
port int
port (int)

Returns

int — a value of this type

bind6

XuAPI
pub fn bind6(fd int, ip string, port int) int

Purpose

IPv6 socket address helpers. `ip` is the 16-byte raw IPv6 value used by net.IP; the runtime validates its length before touching the host socket. Throws on failure.

Parameters

fd int
file descriptor (int)
ip string
ip (string)
port int
port (int)

Returns

int — a value of this type

connect6

XuAPI
pub fn connect6(fd int, ip string, port int) int

Purpose

connect6; returns int. Throws on failure.

Parameters

fd int
file descriptor (int)
ip string
ip (string)
port int
port (int)

Returns

int — a value of this type

bind_unix

XuAPI
pub fn bind_unix(fd int, path string) int

Purpose

Unix-domain pathname sockets. These calls are available on Darwin/Linux the hosted runtime returns an explicit unsupported error on Windows. Throws on failure.

Parameters

fd int
file descriptor (int)
path string
filesystem path (string)

Returns

int — a value of this type

connect_unix

XuAPI
pub fn connect_unix(fd int, path string) int

Purpose

Connect unix. Throws on failure.

Parameters

fd int
file descriptor (int)
path string
filesystem path (string)

Returns

int — a value of this type

listen

XuAPI
pub fn listen(fd int, backlog int) int

Purpose

Listen for connections. Throws on failure.

Parameters

fd int
file descriptor (int)
backlog int
backlog (int)

Returns

int — a value of this type

accept

XuAPI
pub fn accept(fd int) int

Purpose

Accept one connection. Throws on failure.

Parameters

fd int
file descriptor (int)

Returns

int — a value of this type

sendto

XuAPI
pub fn sendto(fd int, addr string, data string) int

Purpose

sendto; returns int. Throws on failure.

Parameters

fd int
file descriptor (int)
addr string
address (string)
data string
data (string)

Returns

int — a value of this type

recvfrom

XuAPI
pub fn recvfrom(fd int, max int) string

Purpose

recvfrom; returns string. Throws on failure.

Parameters

fd int
file descriptor (int)
max int
maximum (int)

Returns

string — result string

fd_read

XuAPI
pub fn fd_read(fd int, max int) string

Purpose

Fd read. Throws on failure.

Parameters

fd int
file descriptor (int)
max int
maximum (int)

Returns

string — result string

fd_write

XuAPI
pub fn fd_write(fd int, data string) int

Purpose

Fd write. Throws on failure.

Parameters

fd int
file descriptor (int)
data string
data (string)

Returns

int — a value of this type

fd_close

XuAPI
pub fn fd_close(fd int) int

Purpose

Fd close. Throws on failure.

Parameters

fd int
file descriptor (int)

Returns

int — a value of this type

socket_read

XuAPI
pub fn socket_read(fd int, max int) string

Purpose

Socket-specific I/O. Generic fd_* maps to file handles on Windows Winsock SOCKETs must instead use recv/send/closesocket. Keep these wrappers private to the net package's higher-level Conn/PacketConn paths. Throws on failure.

Parameters

fd int
file descriptor (int)
max int
maximum (int)

Returns

string — result string

socket_write

XuAPI
pub fn socket_write(fd int, data string) int

Purpose

Socket write. Throws on failure.

Parameters

fd int
file descriptor (int)
data string
data (string)

Returns

int — a value of this type

socket_close

XuAPI
pub fn socket_close(fd int) int

Purpose

Socket close. Throws on failure.

Parameters

fd int
file descriptor (int)

Returns

int — a value of this type

set_sock_timeout

XuAPI
pub fn set_sock_timeout(fd int, ns int) int

Purpose

set_sock_timeout sets SO_SNDTIMEO and SO_RCVTIMEO. ns is relative 0 clears. connect honors it on Darwin; Linux connect still uses SYN retries. read/write honor it on both. Throws on failure.

Parameters

fd int
file descriptor (int)
ns int
ns (int)

Returns

int — a value of this type

interface_data

XuAPI
pub fn interface_data(name string) string

Purpose

interface_data returns the host network-interface snapshot used by the net package. Passing an empty name returns NUL-separated interface names passing a name returns a fixed binary metadata record. Platform ABI structs stay behind this os/runtime boundary. Throws on failure.

Parameters

name string
name (string)

Returns

string — result string

(&File) read_n

XuAPI
pub fn (f &File) read_n(n int) string

Purpose

io.StreamReader/StreamWriter adapters. These use the existing descriptor callers retain responsibility for close and may continue using File APIs. Throws on failure.

Parameters

f &File
receiver &File (borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&File) write_str

XuAPI
pub fn (f &File) write_str(data string) int

Purpose

Method on `&File`: write a string. Throws on failure.

Parameters

f &File
receiver &File (borrow)
data string
data (string)

Returns

int — a value of this type