-
Notifications
You must be signed in to change notification settings - Fork 0
文件操作
Tueo edited this page Mar 21, 2020
·
2 revisions
fopen和open是两套不同的api接口,在linux下的fopen是open的封装函数,fopen最终还是要调用底层的系统调用open。fopen是c/c++标准I/O库函数。open是linux的系统调用。
fopen | fclose | fread | fwrite | freopen | fseek | ftell | rewind |
---|---|---|---|---|---|---|---|
open | close | read | write | ioctl |
fopen与open的区别
- fread是带缓冲的,read不带缓冲。
- fopen是标准c里定义的,open是POSIX中定义的。
- fread可以读一个结构,read在linux/unix中读二进制与普通文件没有区别。
- fopen不能指定要创建文件的权限,open可以指定权限。
- fopen返回文件指针,open返回文件描述符(整数)。
- linux/unix中任何设备都是文件,都可以用open,read。
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
pathname为文件路径,可以是相对路径,也可以是绝对路径。 flags是打开方式,如只读,只写或者读写。 mode指定文件权限