c语言 open函数
c语言 open函数
在 C 语言中,open
是一个用于打开文件的系统调用(属于 POSIX 标准,主要在 Linux/Unix 系统中使用)。它和标准 C 库中的 fopen
不同,open
更底层,直接和操作系统打交道。
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>int open(const char *pathname, int flags); //int open(const char *pathname, int flags, mode_t mode); // 创建文件时用这个返回值:
成功时: 返回一个 非负整数(≥0)
失败时: 返回 -1
(返回具体的值,有待后面具体解释......)
参数说明
参数 | 含义 |
---|---|
pathname | 文件路径,例如 "./ipc/dev_config.txt" |