Rewrote the comments in the libraries under 'includes' in English (excluding those inside folders)
This commit is contained in:
@@ -3,25 +3,25 @@ from stdint import *
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# POSIX 类型别名
|
||||
# 注意:ssize_t 已在 stdint.py 中定义为 t.CPtrDiffT,此处不再重复
|
||||
# POSIX Type Alias
|
||||
# Note: ssize_t has already been defined as t.CPtrDiffT in stdint.py, so we won’t repeat it here.
|
||||
# =============================================================================
|
||||
DIR: t.CTypedef = t.CVoid | t.CPtr # 不透明目录流句柄
|
||||
mode_t: t.CTypedef = t.CUInt32T # 文件模式/权限位
|
||||
pid_t: t.CTypedef = t.CInt32T # 进程 ID
|
||||
off_t: t.CTypedef = t.CInt64T # 文件偏移量(Linux x86_64)
|
||||
dev_t: t.CTypedef = t.CUInt64T # 设备号
|
||||
ino_t: t.CTypedef = t.CUInt64T # inode 号
|
||||
nlink_t: t.CTypedef = t.CUInt64T # 硬链接数
|
||||
uid_t: t.CTypedef = t.CUInt32T # 用户 ID
|
||||
gid_t: t.CTypedef = t.CUInt32T # 组 ID
|
||||
blksize_t: t.CTypedef = t.CInt64T # 文件系统 I/O 块大小
|
||||
blkcnt_t: t.CTypedef = t.CInt64T # 已分配块数
|
||||
time_t: t.CTypedef = t.CInt64T # 日历时间秒数
|
||||
DIR: t.CTypedef = t.CVoid | t.CPtr # Opaque directory stream handle
|
||||
mode_t: t.CTypedef = t.CUInt32T # File mode/permission bits
|
||||
pid_t: t.CTypedef = t.CInt32T # Process ID
|
||||
off_t: t.CTypedef = t.CInt64T # File offset (Linux x86_64)
|
||||
dev_t: t.CTypedef = t.CUInt64T # Device number
|
||||
ino_t: t.CTypedef = t.CUInt64T # inode number
|
||||
nlink_t: t.CTypedef = t.CUInt64T # Hard link count
|
||||
uid_t: t.CTypedef = t.CUInt32T # User ID
|
||||
gid_t: t.CTypedef = t.CUInt32T # Group ID
|
||||
blksize_t: t.CTypedef = t.CInt64T # File I/O block size
|
||||
blkcnt_t: t.CTypedef = t.CInt64T # Allocated block count
|
||||
time_t: t.CTypedef = t.CInt64T # Calendar time seconds
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# open() 标志位
|
||||
# open() Flags
|
||||
# =============================================================================
|
||||
O_RDONLY: t.CDefine = 0
|
||||
O_WRONLY: t.CDefine = 1
|
||||
@@ -35,46 +35,46 @@ O_CLOEXEC: t.CDefine = 0o2000000
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# access() 测试标志
|
||||
# access() Test Flags
|
||||
# =============================================================================
|
||||
F_OK: t.CDefine = 0 # 文件存在
|
||||
R_OK: t.CDefine = 4 # 可读
|
||||
W_OK: t.CDefine = 2 # 可写
|
||||
X_OK: t.CDefine = 1 # 可执行
|
||||
F_OK: t.CDefine = 0 # File exists
|
||||
R_OK: t.CDefine = 4 # Read permission
|
||||
W_OK: t.CDefine = 2 # Write permission
|
||||
X_OK: t.CDefine = 1 # Execute permission
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# stat 结构体的 st_mode 掩码与类型位
|
||||
# stat struct st_mode Mask and Type Bits
|
||||
# =============================================================================
|
||||
S_IFMT: t.CDefine = 0o170000 # 类型掩码
|
||||
S_IFSOCK: t.CDefine = 0o140000 # 套接字
|
||||
S_IFLNK: t.CDefine = 0o120000 # 符号链接
|
||||
S_IFREG: t.CDefine = 0o100000 # 普通文件
|
||||
S_IFBLK: t.CDefine = 0o060000 # 块设备
|
||||
S_IFDIR: t.CDefine = 0o040000 # 目录
|
||||
S_IFCHR: t.CDefine = 0o020000 # 字符设备
|
||||
S_IFIFO: t.CDefine = 0o010000 # FIFO/管道
|
||||
S_IFMT: t.CDefine = 0o170000 # Type mask bits
|
||||
S_IFSOCK: t.CDefine = 0o140000 # Socket
|
||||
S_IFLNK: t.CDefine = 0o120000 # Symbolic link
|
||||
S_IFREG: t.CDefine = 0o100000 # Regular file
|
||||
S_IFBLK: t.CDefine = 0o060000 # Block device
|
||||
S_IFDIR: t.CDefine = 0o040000 # Directory
|
||||
S_IFCHR: t.CDefine = 0o020000 # Character device
|
||||
S_IFIFO: t.CDefine = 0o010000 # FIFO/pipe
|
||||
|
||||
# 权限位
|
||||
S_ISUID: t.CDefine = 0o4000 # set-user-ID
|
||||
S_ISGID: t.CDefine = 0o2000 # set-group-ID
|
||||
S_ISVTX: t.CDefine = 0o1000 # sticky 位
|
||||
S_IRWXU: t.CDefine = 0o700 # 用户读写执行
|
||||
S_IRUSR: t.CDefine = 0o400 # 用户读
|
||||
S_IWUSR: t.CDefine = 0o200 # 用户写
|
||||
S_IXUSR: t.CDefine = 0o100 # 用户执行
|
||||
S_IRWXG: t.CDefine = 0o070 # 组读写执行
|
||||
S_IRGRP: t.CDefine = 0o040 # 组读
|
||||
S_IWGRP: t.CDefine = 0o020 # 组写
|
||||
S_IXGRP: t.CDefine = 0o010 # 组执行
|
||||
S_IRWXO: t.CDefine = 0o007 # 其他读写执行
|
||||
S_IROTH: t.CDefine = 0o004 # 其他读
|
||||
S_IWOTH: t.CDefine = 0o002 # 其他写
|
||||
S_IXOTH: t.CDefine = 0o001 # 其他执行
|
||||
# Permission Bits
|
||||
S_ISUID: t.CDefine = 0o4000 # Set-user-ID
|
||||
S_ISGID: t.CDefine = 0o2000 # Set-group-ID
|
||||
S_ISVTX: t.CDefine = 0o1000 # Sticky bit
|
||||
S_IRWXU: t.CDefine = 0o700 # Read/write/execute permission
|
||||
S_IRUSR: t.CDefine = 0o400 # User read permission
|
||||
S_IWUSR: t.CDefine = 0o200 # User write permission
|
||||
S_IXUSR: t.CDefine = 0o100 # User execute permission
|
||||
S_IRWXG: t.CDefine = 0o070 # Read/write/execute permission
|
||||
S_IRGRP: t.CDefine = 0o040 # Read permission
|
||||
S_IWGRP: t.CDefine = 0o020 # Write
|
||||
S_IXGRP: t.CDefine = 0o010 # Execute
|
||||
S_IRWXO: t.CDefine = 0o007 # Read/write/execute permission
|
||||
S_IROTH: t.CDefine = 0o004 # Other read permission
|
||||
S_IWOTH: t.CDefine = 0o002 # Other write permission
|
||||
S_IXOTH: t.CDefine = 0o001 # Other execute permission
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# lseek() whence 值
|
||||
# lseek() whence values
|
||||
# =============================================================================
|
||||
SEEK_SET: t.CDefine = 0
|
||||
SEEK_CUR: t.CDefine = 1
|
||||
@@ -82,14 +82,14 @@ SEEK_END: t.CDefine = 2
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 路径/名称长度限制
|
||||
# Path/name length limits
|
||||
# =============================================================================
|
||||
PATH_MAX: t.CDefine = 4096
|
||||
NAME_MAX: t.CDefine = 255
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# sysconf() 参数
|
||||
# sysconf() parameters
|
||||
# =============================================================================
|
||||
_SC_NPROCESSORS_ONLN: t.CDefine = 84
|
||||
_SC_PAGESIZE: t.CDefine = 30
|
||||
@@ -97,7 +97,7 @@ _SC_CLK_TCK: t.CDefine = 2
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# dirent 结构体的 d_type 值
|
||||
# dirent struct d_type values
|
||||
# =============================================================================
|
||||
DT_UNKNOWN: t.CDefine = 0
|
||||
DT_FIFO: t.CDefine = 1
|
||||
@@ -111,7 +111,7 @@ DT_WHT: t.CDefine = 14
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# waitpid() 选项
|
||||
# waitpid() options
|
||||
# =============================================================================
|
||||
WNOHANG: t.CDefine = 1
|
||||
WUNTRACED: t.CDefine = 2
|
||||
@@ -119,12 +119,12 @@ WCONTINUED: t.CDefine = 8
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 结构体:Linux x86_64 布局
|
||||
# Struct: Linux x86_64 Layout
|
||||
# =============================================================================
|
||||
|
||||
# struct stat(144 字节,Linux x86_64 glibc 布局)
|
||||
# 注意:st_atim/st_mtim/st_ctim 在 C 中是 struct timespec { tv_sec; tv_nsec; }
|
||||
# 此处拆分为 _sec/_nsec 两个 LONGLONG 字段以保持二进制兼容
|
||||
# struct stat (144 bytes, Linux x86_64 glibc layout)
|
||||
# Note: st_atim/st_mtim/st_ctim in C are struct timespec { tv_sec; tv_nsec; }
|
||||
# Here split into _sec/_nsec two LONGLONG fields to maintain binary compatibility
|
||||
class Stat():
|
||||
st_dev: dev_t # @ 0
|
||||
st_ino: ino_t # @ 8
|
||||
@@ -148,19 +148,19 @@ class Stat():
|
||||
__unused2: LONGLONG # @ 136
|
||||
|
||||
|
||||
# struct dirent(Linux x86_64,d_name 为 char[256])
|
||||
# 注意:d_name 实际是定长 char[256],TransPyC 用 CHARPTR 占位(8 字节)。
|
||||
# 用户通常通过 readdir 返回的只读指针访问,不直接分配 Dirent 结构体。
|
||||
# struct dirent (Linux x86_64, d_name is char[256])
|
||||
# Note: d_name is actually a fixed-length char[256], TransPyC uses CHARPTR as a placeholder (8 bytes).
|
||||
# Users usually access it via the read-only pointer returned by readdir, not by directly allocating a Dirent structure.
|
||||
class Dirent():
|
||||
d_ino: ino_t # @ 0
|
||||
d_off: off_t # @ 8
|
||||
d_reclen: USHORT # @ 16
|
||||
d_type: BYTE # @ 18
|
||||
d_name: CHARPTR # @ 19(实际为 char[256],此处占位)
|
||||
d_name: CHARPTR # @ 19 (actually char[256], this is a placeholder)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 文件操作函数(10 个)
|
||||
# File operations (10)
|
||||
# =============================================================================
|
||||
def open(path: t.CConst | str, oflag: INT, *args) -> INT | t.State: pass
|
||||
def close(fd: INT) -> INT | t.State: pass
|
||||
@@ -175,14 +175,14 @@ def chmod(path: t.CConst | str, mode: mode_t) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# stat 系列(2 个)
|
||||
# stat series (2)
|
||||
# =============================================================================
|
||||
def stat(path: t.CConst | str, buf: Stat | t.CPtr) -> INT | t.State: pass
|
||||
def fstat(fd: INT, buf: Stat | t.CPtr) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 目录操作(6 个)
|
||||
# Directory operations (6)
|
||||
# =============================================================================
|
||||
def opendir(name: t.CConst | str) -> DIR | t.CPtr | t.State: pass
|
||||
def readdir(dirp: DIR | t.CPtr) -> Dirent | t.CPtr | t.State: pass
|
||||
@@ -194,7 +194,7 @@ def chdir(path: t.CConst | str) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 进程/管道(8 个)
|
||||
# Process operations (8)
|
||||
# =============================================================================
|
||||
def fork() -> pid_t | t.State: pass
|
||||
def execvp(file: t.CConst | str, argv: CHARPTR | t.CPtr) -> INT | t.State: pass
|
||||
@@ -207,7 +207,7 @@ def getpid() -> pid_t | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 环境/系统(4 个)
|
||||
# Environment operations (4)
|
||||
# =============================================================================
|
||||
def getenv(name: t.CConst | str) -> CHARPTR | t.State: pass
|
||||
def setenv(name: t.CConst | str, value: t.CConst | str, overwrite: INT) -> INT | t.State: pass
|
||||
@@ -216,10 +216,10 @@ def isatty(fd: INT) -> INT | t.State: pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 内联宏(C 宏,用 TransPyC 普通函数实现,不标记 t.CExtern)
|
||||
# Inline macros (C macros, implemented as normal functions, not marked as t.CExtern)
|
||||
# =============================================================================
|
||||
|
||||
# st_mode 类型判定
|
||||
# st_mode type determination
|
||||
def S_ISREG(mode: mode_t) -> bool:
|
||||
return (mode & S_IFMT) == S_IFREG
|
||||
|
||||
@@ -248,7 +248,7 @@ def S_ISSOCK(mode: mode_t) -> bool:
|
||||
return (mode & S_IFMT) == S_IFSOCK
|
||||
|
||||
|
||||
# waitpid 状态解析
|
||||
# waitpid status parsing
|
||||
def WIFEXITED(status: INT) -> bool:
|
||||
return (status & 0x7F) == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user