UNIX I/O摘要

本文详细介绍了intopen函数的使用方法,该函数用于将文件名转换为文件描述符,并返回描述符编号。描述符总是返回当前进程中未打开的最小描述符。文章解释了不同标志参数的作用,如O_RDONLY、O_WRONLY、O_RDWR等,并介绍了附加标志,例如O_CREAT、O_TRUNC和O_APPEND的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

int open(char *filename, int flag, mode_t mode);

The open function converts a file name to a file descriptor and returns the
descriptor number. The descriptor returned is always the smallest descriptor that
is not currently open in the process. The flags argument indicates how the process
intends to access the file:

O_RDONLY: Reading only
O_WRONLY: Writing only
O_RDWR: Reading and writing

The flags argument can also be or’d with one or more bit masks that provide
additional instructions for writing:
O_CREAT: If the file does not exist, then create a truncated (empty) version
of it.
O_TRUNC: If the file already exists, then truncate it.
O_APPEND: Before each write operation, set the file position to the end of
the file.

The mode argument specifies the access permission bits of new files. The
symbolic names for these bits are shown in Figure 10.1. As part of its context,
each process has a umask that is set by calling the umask function. When a process
creates a new file by calling the open function with some mode argument, then the
access permission bits of the file are set to mode & ~umask.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值