XU XUv0.8.8
EN

API

#os

import: #os

counts: 73 函数, 16 方法, 5 类型, 9 常量, 0 方法集

进程、文件、环境。hosted 下 File:open/create/read/write/close。getwd 失败返空串。

args

XuAPI
pub fn args() []string

用途

args,返回 []string。

参数

无

返回

[]string — 切片结果

argv

XuAPI
pub fn argv() []string

用途

命令行参数。

参数

无

返回

[]string — 切片结果

read

XuAPI
pub fn read(path string) string

用途

读出最多 max 字节。失败时 throw。

参数

path string
文件系统路径(string)

返回

string — 结果字符串

write

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

用途

写入数据,返回写入的字节数。失败时 throw。

参数

path string
文件系统路径(string)
data string
数据(string)

返回

int — 写入的字节数

struct File

XuAPI
pub struct File {

}

用途

公开结构体 `File`。

参数

无

const o_rdonly

XuAPI
pub const o_rdonly = 0

用途

公开常量 `o_rdonly`。 值为 `0`

参数

无

const o_create

XuAPI
pub const o_create = 1

用途

公开常量 `o_create`。 值为 `1`

参数

无

const o_append

XuAPI
pub const o_append = 2

用途

公开常量 `o_append`。 值为 `2`

参数

无

const o_excl

XuAPI
pub const o_excl = 3

用途

公开常量 `o_excl`。 值为 `3`

参数

无

const o_lock

XuAPI
pub const o_lock = 4

用途

公开常量 `o_lock`。 值为 `4`

参数

无

const o_lock_existing

XuAPI
pub const o_lock_existing = 5

用途

公开常量 `o_lock_existing`。 值为 `5`

参数

无

open_lock

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

用途

打开加锁。失败时 throw。

参数

path string
文件系统路径(string)
existing bool
existing(bool)

返回

File — 该类型的值

open

XuAPI
pub fn open(path string) File

用途

打开。失败时 throw。

参数

path string
文件系统路径(string)

返回

File — 该类型的值

create

XuAPI
pub fn create(path string) File

用途

创建。失败时 throw。

参数

path string
文件系统路径(string)

返回

File — 该类型的值

open_append

XuAPI
pub fn open_append(path string) File

用途

打开append。失败时 throw。

参数

path string
文件系统路径(string)

返回

File — 该类型的值

create_excl

XuAPI
pub fn create_excl(path string) File

用途

创建excl。失败时 throw。

参数

path string
文件系统路径(string)

返回

File — 该类型的值

(&File) read

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

用途

`&File` 上的方法:读出最多 max 字节。失败时 throw。

参数

f &File
接收者 &File(借用)
max int
上限(int)

返回

string — 结果字符串

(&File) write

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

用途

`&File` 上的方法:写入数据,返回写入的字节数。失败时 throw。

参数

f &File
接收者 &File(借用)
data string
数据(string)

返回

int — 写入的字节数

(&mut File) close

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

用途

`&mut File` 上的方法:关闭资源。失败时 throw。

参数

f &mut File
接收者 &mut File(可变借用)

返回

int — 该类型的值

const seek_set

XuAPI
pub const seek_set = 0

用途

公开常量 `seek_set`。 值为 `0`

参数

无

const seek_cur

XuAPI
pub const seek_cur = 1

用途

公开常量 `seek_cur`。 值为 `1`

参数

无

const seek_end

XuAPI
pub const seek_end = 2

用途

公开常量 `seek_end`。 值为 `2`

参数

无

(&File) seek

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

用途

`&File` 上的方法:按 whence 把读位置移到 offset。whence 0/1/2 分别为绝对、相对、从末尾。失败时 throw。

参数

f &File
接收者 &File(借用)
offset int
偏移(int)
whence int
定位基准:0 起点 / 1 当前 / 2 末尾(int)

返回

int — 该类型的值

struct Pipe

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

用途

公开结构体 `Pipe`。

参数

r File
rune(Unicode 码点)
w File
写入侧 / 宽度

pipe

XuAPI
pub fn pipe() Pipe

用途

pipe,返回 Pipe。失败时 throw。

参数

无

返回

Pipe — 该类型的值

read_dir

XuAPI
pub fn read_dir(path string) string

用途

列目录。失败时 throw。

参数

path string
文件系统路径(string)

返回

string — 结果字符串

listdir

XuAPI
pub fn listdir(path string) string

用途

列出目录(文本)。失败时 throw。

参数

path string
文件系统路径(string)

返回

string — 结果字符串

getpid

XuAPI
pub fn getpid() int

用途

进程 id。

参数

无

返回

int — 该类型的值

getppid

XuAPI
pub fn getppid() int

用途

父进程 id。

参数

无

返回

int — 该类型的值

getuid

XuAPI
pub fn getuid() int

用途

用户 id。

参数

无

返回

int — 该类型的值

getgid

XuAPI
pub fn getgid() int

用途

组 id。

参数

无

返回

int — 该类型的值

geteuid

XuAPI
pub fn geteuid() int

用途

有效用户 id。

参数

无

返回

int — 该类型的值

getegid

XuAPI
pub fn getegid() int

用途

有效组 id。

参数

无

返回

int — 该类型的值

getpagesize

XuAPI
pub fn getpagesize() int

用途

页大小。

参数

无

返回

int — 该类型的值

hostname

XuAPI
pub fn hostname() string

用途

主机名。

参数

无

返回

string — 结果字符串

getwd

XuAPI
pub fn getwd() string

用途

工作目录。

参数

无

返回

string — 结果字符串

getenv

XuAPI
pub fn getenv(name string) string

用途

读环境变量。

参数

name string
名字(string)

返回

string — 结果字符串

struct EnvVal

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

用途

公开结构体 `EnvVal`。

参数

value string
字段(string)
found bool
字段(bool)

lookup_env

XuAPI
pub fn lookup_env(name string) EnvVal

用途

查找env。

参数

name string
名字(string)

返回

EnvVal — 该类型的值

environ

XuAPI
pub fn environ() []string

用途

环境变量表。

参数

无

返回

[]string — 切片结果

temp_dir

XuAPI
pub fn temp_dir() string

用途

临时目录。

参数

无

返回

string — 结果字符串

home_dir

XuAPI
pub fn home_dir() string

用途

家目录。

参数

无

返回

string — 结果字符串

user_home_dir

XuAPI
pub fn user_home_dir() string

用途

用户家目录目录部分。失败时 throw。

参数

无

返回

string — 结果字符串

path_separator

XuAPI
pub fn path_separator() int

用途

路径分隔符。

参数

无

返回

int — 该类型的值

is_path_separator

XuAPI
pub fn is_path_separator(c int) bool

用途

是否路径分隔符。

参数

c int
字节或字符码(int)

返回

bool — 是否成立

path_list_separator

XuAPI
pub fn path_list_separator() int

用途

pathlistseparator。

参数

无

返回

int — 该类型的值

dev_null

XuAPI
pub fn dev_null() string

用途

devnull。

参数

无

返回

string — 结果字符串

user_cache_dir

XuAPI
pub fn user_cache_dir() string

用途

用户缓存目录。失败时 throw。

参数

无

返回

string — 结果字符串

user_config_dir

XuAPI
pub fn user_config_dir() string

用途

用户配置目录。失败时 throw。

参数

无

返回

string — 结果字符串

stat

XuAPI
pub fn stat(path string) FileInfo

用途

读取元信息。失败时 throw。

参数

path string
文件系统路径(string)

返回

FileInfo — 该类型的值

mkdir

XuAPI
pub fn mkdir(path string) int

用途

创建目录。失败时 throw。

参数

path string
文件系统路径(string)

返回

int — 该类型的值

rename

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

用途

重命名。失败时 throw。

参数

old string
旧值 / 被替换片段(string)
new string
新值 / 替换成的片段(string)

返回

int — 该类型的值

remove

XuAPI
pub fn remove(path string) int

用途

删除。失败时 throw。

参数

path string
文件系统路径(string)

返回

int — 该类型的值

chmod

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

用途

改权限。失败时 throw。

参数

path string
文件系统路径(string)
mode int
模式(int)

返回

int — 该类型的值

chdir

XuAPI
pub fn chdir(path string) int

用途

改目录。失败时 throw。

参数

path string
文件系统路径(string)

返回

int — 该类型的值

is_dir

XuAPI
pub fn is_dir(path string) bool

用途

是否为目录。

参数

path string
文件系统路径(string)

返回

bool — 是否成立

is_not_exist

XuAPI
pub fn is_not_exist(msg string) bool

用途

是否不存在类错误。

参数

msg string
消息(string)

返回

bool — 是否成立

is_exist

XuAPI
pub fn is_exist(msg string) bool

用途

是否已存在类错误。

参数

msg string
消息(string)

返回

bool — 是否成立

is_permission

XuAPI
pub fn is_permission(msg string) bool

用途

判断是否 permission。

参数

msg string
消息(string)

返回

bool — 是否成立

is_timeout

XuAPI
pub fn is_timeout(msg string) bool

用途

判断是否 timeout。

参数

msg string
消息(string)

返回

bool — 是否成立

struct DirEntry

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

用途

公开结构体 `DirEntry`。

参数

name string
名字
is_dir bool
字段(bool)

entries

XuAPI
pub fn entries(path0 string) []DirEntry

用途

列出目录项。失败时 throw。

参数

path0 string
path0(string)

返回

[]DirEntry — 切片结果

mkdir_all

XuAPI
pub fn mkdir_all(path0 string) int

用途

递归建目录。失败时 throw。

参数

path0 string
path0(string)

返回

int — 该类型的值

mkdir_temp

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

用途

建临时目录。失败时 throw。

参数

dir string
目录(string)
pattern string
匹配模式(string)

返回

string — 结果字符串

create_temp

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

用途

建临时文件。失败时 throw。

参数

dir string
目录(string)
pattern string
匹配模式(string)

返回

string — 结果字符串

remove_all

XuAPI
pub fn remove_all(path0 string) int

用途

递归删除。

参数

path0 string
path0(string)

返回

int — 该类型的值

expand_env

XuAPI
pub fn expand_env(s &string) string

用途

展开 $VAR。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

closed_file

XuAPI
pub fn closed_file() File

用途

closed文件。

参数

无

返回

File — 该类型的值

(&mut File) take

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

用途

在 `&mut File` 上调用 `take`。失败时 throw。

参数

f &mut File
接收者 &mut File(可变借用)

返回

File — 该类型的值

(&mut File) release_descriptor

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

用途

`&mut File` 上的方法:releasedescriptor。失败时 throw。

参数

f &mut File
接收者 &mut File(可变借用)

返回

int — 该类型的值

(&File) descriptor

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

用途

在 `&File` 上调用 `descriptor`。失败时 throw。

参数

f &File
接收者 &File(借用)

返回

int — 该类型的值

struct DirFS

XuAPI
pub struct DirFS {
    pub dir string
}

用途

公开结构体 `DirFS`。

参数

dir string
目录

dir_fs

XuAPI
pub fn dir_fs(dir string) DirFS

用途

目录文件系统。

参数

dir string
目录(string)

返回

DirFS — 该类型的值

(&DirFS) open

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

用途

`&DirFS` 上的方法:打开。失败时 throw。

参数

d &DirFS
接收者 &DirFS(借用)
name string
名字(string)

返回

File — 该类型的值

(&DirFS) stat

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

用途

`&DirFS` 上的方法:读取元信息。失败时 throw。

参数

d &DirFS
接收者 &DirFS(借用)
name string
名字(string)

返回

FileInfo — 该类型的值

(&DirFS) read_dir

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

用途

`&DirFS` 上的方法:列目录。失败时 throw。

参数

d &DirFS
接收者 &DirFS(借用)
name string
名字(string)

返回

[]DirEntry — 切片结果

(&DirFS) read_file

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

用途

`&DirFS` 上的方法:读文件。失败时 throw。

参数

d &DirFS
接收者 &DirFS(借用)
name string
名字(string)

返回

string — 结果字符串

(&DirFS) sub

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

用途

`&DirFS` 上的方法:相减。失败时 throw。

参数

d &DirFS
接收者 &DirFS(借用)
name string
名字(string)

返回

DirFS — 该类型的值

(&File) read_result

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

用途

`&File` 上的方法:读取结果。

参数

f &File
接收者 &File(借用)
n int
数量、长度或上限(int)

返回

io.ReadResult — 该类型的值

(&File) write_result

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

用途

`&File` 上的方法:写入结果。

参数

f &File
接收者 &File(借用)
data string
数据(string)

返回

io.WriteResult — 该类型的值

socket

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

用途

套接字。失败时 throw。

参数

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

返回

int — 该类型的值

bind4

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

用途

IPv4 bind。失败时 throw。

参数

fd int
文件描述符(int)
a int
值(int)
b int
b(int)
c int
字节或字符码(int)
d int
d(int)
port int
端口(int)

返回

int — 该类型的值

connect4

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

用途

IPv4 connect。失败时 throw。

参数

fd int
文件描述符(int)
a int
值(int)
b int
b(int)
c int
字节或字符码(int)
d int
d(int)
port int
端口(int)

返回

int — 该类型的值

bind6

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

用途

bind6,返回 int。失败时 throw。

参数

fd int
文件描述符(int)
ip string
ip(string)
port int
端口(int)

返回

int — 该类型的值

connect6

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

用途

connect6,返回 int。失败时 throw。

参数

fd int
文件描述符(int)
ip string
ip(string)
port int
端口(int)

返回

int — 该类型的值

bind_unix

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

用途

bindUnix 时间。失败时 throw。

参数

fd int
文件描述符(int)
path string
文件系统路径(string)

返回

int — 该类型的值

connect_unix

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

用途

connectUnix 时间。失败时 throw。

参数

fd int
文件描述符(int)
path string
文件系统路径(string)

返回

int — 该类型的值

listen

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

用途

开始监听。失败时 throw。

参数

fd int
文件描述符(int)
backlog int
backlog(int)

返回

int — 该类型的值

accept

XuAPI
pub fn accept(fd int) int

用途

接受一个连接。失败时 throw。

参数

fd int
文件描述符(int)

返回

int — 该类型的值

sendto

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

用途

发送数据报。失败时 throw。

参数

fd int
文件描述符(int)
addr string
地址(string)
data string
数据(string)

返回

int — 该类型的值

recvfrom

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

用途

收数据报。失败时 throw。

参数

fd int
文件描述符(int)
max int
上限(int)

返回

string — 结果字符串

fd_read

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

用途

从 fd 读。失败时 throw。

参数

fd int
文件描述符(int)
max int
上限(int)

返回

string — 结果字符串

fd_write

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

用途

向 fd 写。失败时 throw。

参数

fd int
文件描述符(int)
data string
数据(string)

返回

int — 该类型的值

fd_close

XuAPI
pub fn fd_close(fd int) int

用途

关 fd。失败时 throw。

参数

fd int
文件描述符(int)

返回

int — 该类型的值

socket_read

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

用途

读取套接字。失败时 throw。

参数

fd int
文件描述符(int)
max int
上限(int)

返回

string — 结果字符串

socket_write

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

用途

写入套接字。失败时 throw。

参数

fd int
文件描述符(int)
data string
数据(string)

返回

int — 该类型的值

socket_close

XuAPI
pub fn socket_close(fd int) int

用途

关闭套接字。失败时 throw。

参数

fd int
文件描述符(int)

返回

int — 该类型的值

set_sock_timeout

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

用途

设置 sock timeout。失败时 throw。

参数

fd int
文件描述符(int)
ns int
ns(int)

返回

int — 该类型的值

interface_data

XuAPI
pub fn interface_data(name string) string

用途

网卡data。失败时 throw。

参数

name string
名字(string)

返回

string — 结果字符串

(&File) read_n

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

用途

`&File` 上的方法:最多读 n 字节;到末尾可返回更短或空串。失败时 throw。

参数

f &File
接收者 &File(借用)
n int
数量、长度或上限(int)

返回

string — 结果字符串

(&File) write_str

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

用途

`&File` 上的方法:写入字符串。失败时 throw。

参数

f &File
接收者 &File(借用)
data string
数据(string)

返回

int — 该类型的值