低级别 I/OLow-Level I/O

这些函数将为低于流 I/O 提供的操作的低级别操作直接调用操作系统。These functions invoke the operating system directly for lower-level operation than that provided by stream I/O. 低级别输入和输出调用不会缓冲数据或设置数据格式。Low-level input and output calls do not buffer or format data.

低级别例程可以使用以下预定义的文件描述符访问程序启动时打开的标准流。Low-level routines can access the standard streams opened at program startup using the following predefined file descriptors.

Stream 文件描述符File Descriptor
stdin 00
stdout 11
stderr 22

发生错误时,低级别 I/O 例程将设置 errno 全局变量。Low-level I/O routines set the errno global variable when an error occurs. 只有在程序需要 STDIO.H 中定义的常量(例如文件尾指示符 (EOF))时,在使用低级别函数时必须将 STDIO.H 包含在内。You must include STDIO.H when you use low-level functions only if your program requires a constant that is defined in STDIO.H, such as the end-of-file indicator (EOF).

低级别 I/O 函数Low-Level I/O Functions

函数Function 使用Use
_close_close 关闭文件Close file
_commit_commit 将文件刷新到磁盘Flush file to disk
_creat、_wcreat_creat, _wcreat 创建文件Create file
_dup_dup 返回给定文件的下一个可用文件描述符Return next available file descriptor for given file
_dup2_dup2 为给定文件创建第二个描述符Create second descriptor for given file
_eof_eof 测试文件尾Test for end of file
_lseek、_lseeki64_lseek, _lseeki64 将文件指针重新定位到给定位置Reposition file pointer to given location
_open、_wopen_open, _wopen 打开文件Open file
_read_read 读取文件中的数据Read data from file
_sopen, _wsopen, _sopen_s, _wsopen_s_sopen, _wsopen, _sopen_s, _wsopen_s 打开用于文件共享的文件Open file for file sharing
_tell、_telli64_tell, _telli64 获取当前文件指针位置Get current file-pointer position
_umask, _umask_s_umask, _umask_s 设置文件权限掩码Set file-permission mask
_write_write 将数据写入文件Write data to file

_dup_dup2 通常用于将预定义文件描述符与其他文件关联。_dup and _dup2 are typically used to associate the predefined file descriptors with different files.

另请参阅See Also

输入和输出 Input and Output
按类别分的运行时例程 Run-Time Routines by Category
系统调用System Calls