std.posix 包

功能介绍

posix 包主要适配 POSIX 系统接口。

本包提供多平台统一操控能力,目前支持 Linux 平台,macOS 平台,Windows 平台与 HarmonyOS 平台。

注意

未来版本即将废弃本包全部内容。

API 列表

函数

函数名功能支持平台
open(String, Int32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux Windows macOS HarmonyOS
open(String, Int32, UInt32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux Windows macOS HarmonyOS
access(String, Int32) (deprecated)判断某个文件是否具有某种权限,具有返回 0,否则返回 -1Linux Windows macOS HarmonyOS
chdir(String) (deprecated)通过指定路径的方式,更改调用进程的当前工作目录。Linux Windows macOS HarmonyOS
chmod(String, UInt32) (deprecated)修改文件访问权限。Linux Windows macOS HarmonyOS
chown(String, UInt32, UInt32) (deprecated)修改文件所有者和文件所有者所属组。Linux macOS HarmonyOS
close(Int32) (deprecated)关闭文件,close 将会触发数据写回磁盘,并释放文件占用的资源。Linux Windows macOS HarmonyOS
creat(String, UInt32) (deprecated)创建文件并为其返回文件描述符,或在失败时返回 -1Linux Windows macOS HarmonyOS
dup(Int32) (deprecated)用于复制旧 fd 参数指定的文件描述符并返回。Linux Windows macOS HarmonyOS
dup2(Int32, Int32) (deprecated)用于复制 oldfd 参数指定的文件描述符,并将其返回到 newfd 参数。Linux Windows macOS HarmonyOS
faccessat(Int32, String, Int32, Int32) (deprecated)判断 fd 对应的文件是否具有某种权限,具有返回 0,否则返回 -1Linux macOS HarmonyOS
fchdir(Int32) (deprecated)通过指定文件路径的描述符,更改调用进程的当前工作目录。Linux macOS HarmonyOS
fchmod(Int32, UInt32) (deprecated)修改文件描述符对应的文件访问权限。Linux Windows macOS HarmonyOS
fchmodat(Int32, String, UInt32, Int32) (deprecated)修改文件描述符对应的文件访问权限。Linux Windows macOS HarmonyOS
fchown(Int32, UInt32, UInt32) (deprecated)修改 fd 对应的文件所有者和文件所有者所属组。Linux macOS HarmonyOS
fchownat(Int32, String, UInt32, UInt32, Int32) (deprecated)修改文件描述符对应的文件所有者和文件所有者所属组。Linux macOS HarmonyOS
getcwd() (deprecated)获取当前执行进程工作目录的绝对路径。Linux Windows macOS HarmonyOS
getgid() (deprecated)获取用户组 IDLinux macOS HarmonyOS
getgroups(Int32, CPointer<UInt32>) (deprecated)获取当前用户所属组的代码。Linux macOS HarmonyOS
gethostname() (deprecated)获取主机名称,此名称通常是 TCP/IP 网络上主机的名称。Linux macOS HarmonyOS
getlogin() (deprecated)获取当前登录名。Linux macOS HarmonyOS
getos() (deprecated)/proc/version 文件中获取 Linux 系统的信息。Linux
getpgid(Int32) (deprecated)获取 pid 指定的进程的 PGID,如果 pid 为零,返回调用进程的进程 IDLinux macOS HarmonyOS
getpgrp() (deprecated)获取调用进程的父进程 IDLinux macOS HarmonyOS
getpid() (deprecated)获取调用进程的进程 ID(PID)Linux Windows macOS HarmonyOS
getppid() (deprecated)获取调用进程的父进程 IDLinux macOS HarmonyOS
getuid() (deprecated)获取调用进程的真实用户 IDLinux macOS HarmonyOS
isBlk(String) (deprecated)检查传入对象是否为块设备,并返回布尔类型。Linux Windows macOS HarmonyOS
isChr(String) (deprecated)检查传入对象是否为字符设备,返回布尔类型。Linux Windows macOS HarmonyOS
isDir(String) (deprecated)检查传入对象是否为文件夹,返回布尔类型。Linux Windows macOS HarmonyOS
isFIFO(String) (deprecated)检查传入对象是否为 FIFO 文件,返回布尔类型。Linux macOS HarmonyOS
isLnk(String) (deprecated)检查传入对象是否为软链路,返回布尔类型。Linux macOS HarmonyOS
isReg(String) (deprecated)检查传入对象是否为普通文件,返回布尔类型。Linux Windows macOS HarmonyOS
isSock(String) (deprecated)检查传入对象是否为套接字文件,返回布尔类型。Linux macOS HarmonyOS
isType(String, UInt32) (deprecated)检查文件是否为指定模式的文件。Linux macOS HarmonyOS
isatty(Int32) (deprecated)用于测试文件描述符是否引用终端,成功时返回 true,否则返回 falseLinux Windows macOS HarmonyOS
kill(Int32, Int32) (deprecated)系统调用可用于向任何进程组或进程发送任何信号。Linux macOS HarmonyOS
killpg(Int32, Int32) (deprecated)将信号 sig 发送到进程组 pgrp,如果 pgrp0,则 killpg() 将信号发送到调用进程的进程组。Linux macOS HarmonyOS
lchown(String, UInt32, UInt32) (deprecated)修改文件链接本身所有者和所有者所属组。Linux macOS
link(String, String) (deprecated)为存在的文件创建链接,一个文件可以有多个指向其 i-node 的目录条目。Linux macOS HarmonyOS
linkat(Int32, String, Int32, String, Int32) (deprecated)创建相对于目录文件描述符的文件链接。Linux macOS HarmonyOS
lseek(Int32, Int64, Int32) (deprecated)当文件进行读或写时,读或写位置相应增加。Linux Windows macOS HarmonyOS
nice(Int32) (deprecated)更改当前线程的优先级。Linux macOS HarmonyOS
open64(String, Int32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux HarmonyOS
open64(String, Int32, UInt32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux HarmonyOS
openat(Int32, String, Int32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux macOS HarmonyOS
openat(Int32, String, Int32, UInt32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux macOS HarmonyOS
openat64(Int32, String, Int32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux macOS HarmonyOS
openat64(Int32, String, Int32, UInt32) (deprecated)打开文件并为其返回新的文件描述符,或在失败时返回 -1Linux macOS HarmonyOS
pread(Int32, CPointer<UInt8>, UIntNative, Int32) (deprecated)fd 指向的文件的 nbyte 字节传输到 buffer 指向的内存中。Linux macOS HarmonyOS
pwrite(Int32, CPointer<UInt8>, UIntNative, Int32) (deprecated)buffer 指向的内存中 nbyte 字节从指定偏移位置开始写入到 fd 指向的文件。Linux macOS HarmonyOS
read(Int32, CPointer<UInt8>, UIntNative) (deprecated)fd 指向的文件的 nbyte 字节传输到 buffer 指向的内存中。Linux Windows macOS HarmonyOS
remove(String) (deprecated)删除文件或目录。Linux Windows macOS HarmonyOS
rename(String, String) (deprecated)重命名文件,如果需要将会移动文件所在目录。Linux Windows macOS HarmonyOS
renameat(Int32, String, Int32, String) (deprecated)重命名文件,如果需要将会移动文件所在目录。Linux macOS HarmonyOS
setgid(UInt32) (deprecated)设置调用进程的有效组 ID,需要适当的权限。Linux macOS
sethostname(String) (deprecated)设置主机名,仅超级用户可以调用。Linux macOS
setpgid(Int32, Int32) (deprecated)此函数将参数 pid 指定的组 ID 设置为参数 pgrp 指定的组 IDLinux macOS HarmonyOS
setpgrp() (deprecated)将当前进程所属的组 ID 设置为当前进程的进程 ID,此函数等同于调用 setpgid(0, 0)。Linux macOS HarmonyOS
setuid(UInt32) (deprecated)设置调用进程的有效用户 ID,需要适当的权限。Linux macOS
symlink(String, String) (deprecated)创建一个名为 symPath 链接到 path 所指定的文件。Linux macOS HarmonyOS
symlinkat(String, Int32, String) (deprecated)创建一个名为 symPath 链接到 pathfd 所指定的文件。Linux macOS HarmonyOS
ttyname(Int32) (deprecated)返回终端名称。Linux Windows macOS HarmonyOS
umask(UInt32) (deprecated)设置权限掩码。Linux Windows macOS HarmonyOS
unlink(String) (deprecated)从文件系统中删除文件。Linux macOS HarmonyOS
unlinkat(Int32, String, Int32) (deprecated)从文件系统中删除文件。Linux macOS HarmonyOS
write(Int32, CPointer<UInt8>, UIntNative) (deprecated)buffer 指向的内存中 nbyte 字节写入到 fd 指向的文件。Linux Windows macOS HarmonyOS

常量

常量名功能支持平台
AT_EMPTY_PATH (deprecated)表示在文件系统中空路径(即没有指定任何文件或目录)时返回的文件描述符,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows HarmonyOS
AT_REMOVEDIR (deprecated)如果指定了 AT_REMOVEDIR 标志,则对 pathname 执行等效于 rmdir(2) 的操作,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_CLOEXEC (deprecated)在某些多线程程序中,使用此标志是必不可少的。因为在一个线程同时打开文件描述符,而另一个线程执行 fork(2)execve(2) 场景下使用单独的 fcntl(2) F_SETFD 操作设置 FD_CLOEXEC 标志并不足以避免竞争条件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_DIRECTORY (deprecated)如果 pathname 指定的文件不是目录,则打开文件失败,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_CREAT (deprecated)如果要打开的文件不存在,则自动创建该文件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_DSYNC (deprecated)每次写入都会等待物理 I/O 完成,但如果写操作不影响读取刚写入的数据,则不等待文件属性更新,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_EXCL (deprecated)如同时设置 O_CREAT,则此指令检查文件是否存在。如果文件不存在,则创建文件。否则,打开文件出错。此外,如果同时设置了 O_CREATO_EXCL,并且要打开的文件是符号链接,则打开文件失败,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_NOCTTY (deprecated)如要打开的文件是终端设备,则该文件不会成为这个进程的控制终端,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_NOFOLLOW (deprecated)pathname 指定的文件是单符号链接,则打开文件失败,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_NONBLOCK (deprecated)以非阻塞的方式打开文件,即 I/O 操作不会导致调用进程等待,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_SYNC (deprecated)同步打开文件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux macOS HarmonyOS
O_RDONLY (deprecated)以只读方式打开文件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_RDWR (deprecated)以读写模式打开文件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_WRONLY (deprecated)以只写方式打开文件,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_APPEND (deprecated)读取或写入文件时,数据将从文件末尾移动。即写入的数据将附加到文件的末尾,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
O_RSYNC (deprecated)此标志仅影响读取操作,必须与 O_SYNCO_DSYNC 结合使用。如果有必要,它将导致读取调用阻塞,直到正在读取的数据(可能还有元数据)刷新到磁盘,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux HarmonyOS
O_TRUNC (deprecated)如果文件存在且打开可写,则此标志将文件长度清除为 0,文件中以前存储的数据消失,适用函数 openopen64openatopenat64,所属函数参数 oflagLinux Windows macOS HarmonyOS
R_OK (deprecated)测试文件读权限,适用函数 accessfaccessat,所属函数参数 modeLinux Windows macOS HarmonyOS
W_OK (deprecated)测试文件写权限,适用函数 accessfaccessat,所属函数参数 modeLinux Windows macOS HarmonyOS
X_OK (deprecated)测试文件执行权限,适用函数 accessfaccessat,所属函数参数 modeLinux Windows macOS HarmonyOS
F_OK (deprecated)测试文件是否存在,适用函数 accessfaccessat,所属函数参数 modeLinux Windows macOS HarmonyOS
SEEK_SET (deprecated)偏移参数表示新的读写位置,适用函数 lseek,所属函数参数 whenceLinux Windows macOS HarmonyOS
SEEK_CUR (deprecated)向当前读或写位置添加偏移量,适用函数 lseek,所属函数参数 whenceLinux Windows macOS HarmonyOS
SEEK_END (deprecated)将读写位置设置为文件末尾,并添加偏移量,适用函数 lseek,所属函数参数 whenceLinux Windows macOS HarmonyOS
SIGABRT (deprecated)异常终止,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGBUS (deprecated)硬件故障,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGFPE (deprecated)算术错误,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGKILL (deprecated)终止,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGCONT (deprecated)暂停过程的继续,默认操作继续或忽略,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGHUP (deprecated)连接已断开,默认操作已终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGINT (deprecated)终端中断字符,默认动作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGQUIT (deprecated)终端退出字符,默认动作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGILL (deprecated)硬件指令无效,默认动作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGTRAP (deprecated)硬件故障,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGIOT (deprecated)硬件故障,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGIO (deprecated)异步 IO,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGPIPE (deprecated)写入未读进程的管道,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGALRM (deprecated)计时器到期,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGPWR (deprecated)电源故障或重启,系统调用无效,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows HarmonyOS
SIGSEGV (deprecated)内存引用无效,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGSTOP (deprecated)停止,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGTERM (deprecated)终止,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGSTKFLT (deprecated)协处理器堆栈故障,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows HarmonyOS
SIGCHLD (deprecated)子进程状态更改,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGTSTP (deprecated)终端停止符号,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGTTIN (deprecated)后台读取控件 tty,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGTTOU (deprecated)后台写控制 tty,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGURG (deprecated)紧急情况(套接字),忽略默认操作,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGUSR1 (deprecated)用户定义的信号,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGUSR2 (deprecated)用户定义的信号,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGVTALRM (deprecated)虚拟时间警报,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGPROF (deprecated)摘要超时,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGWINCH (deprecated)终端窗口大小更改,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGXCPU (deprecated)CPU 占用率超过上限,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
SIGXFSZ (deprecated)文件长度超过上限,默认操作终止,适用函数 killkillpg,所属函数参数 sigLinux Windows macOS HarmonyOS
S_IRUSR (deprecated)表示文件所有者具有读权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IWUSR (deprecated)表示文件所有者具有写权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IRGRP (deprecated)表示文件用户组具有读权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IWGRP (deprecated)表示文件用户组具有写权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IFREG (deprecated)文件类型为一般文件,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFBLK (deprecated)文件类型为块设备,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFDIR (deprecated)文件类型为目录,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFCHR (deprecated)文件类型为字符设备,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFIFO (deprecated)文件类型为 FIFO 文件,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFLNK (deprecated)文件类型为软连接,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IFSOCK (deprecated)文件类型为套接字文件,适用函数 isType, 所属函数参数 modeLinux Windows macOS HarmonyOS
S_IROTH (deprecated)表示其他用户对文件具有读权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IRWXG (deprecated)表示文件用户组具有读、写、执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IRWXU (deprecated)表示文件所有者具有读、写和执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IWOTH (deprecated)表示其他用户对文件具有写权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IXOTH (deprecated)表示其他用户对文件具有执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IRWXO (deprecated)表示其他用户对文件具有读、写和执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IXGRP (deprecated)表示文件用户组具有执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS
S_IXUSR (deprecated)表示文件所有者具有执行权限,适用函数 openopen64openatopenat64chmod(mode)fchmod(mode)fchmodat(mode)creat, 所属函数参数 flagLinux Windows macOS HarmonyOS