1.打开文件
open
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
参数:
pathname:文件路径
flags:打开方式
必须包含:O_RDONLY、O_WRONLY、O_RDWR 三个其中之一
O_CREAT 文件不存在创建
O_TRUNC 文件存在清0
O_APPEND 追加
O_EXCL 文件存在报错
O_NONBLOCK 非阻塞
O_ASYNC 异步IO
mode:权限
只要有O_CREAT标识,表示需要加上权限:
rwx rwx rwx
rw- rw- r--
110 110 100
八进制: 0 6 6 4
2.文件描述符:很小的非负整数,而且新的文件描述符总是尚未被使用的最小的非负整数
3.
0 STDIN_FILENO -> stdin
1 STDOUT_FILENO -> stdout
2 STDERR_FILENO -> stderr
4.标准IO和文件IO的区别
fopen -> open
fgetc/fputc -> read/write
fgets/fputs
fscanf/fprintf
fread/fwrite
fclose -> close
fseek -> lseek
rewind
ftell
1.标准IO是库函数
2.文件IO是系统调用
3.标准IO是针对于文件IO的封装
4.标准IO是有缓存的
5.文件IO是没有缓存的
6.标准IO主要用于操作普通文件
7.文件IO可以操作设备文件、进程间通信的文件、普通文件(Linux系统下的一切文件均可以使用文件IO)
库函数:是针对于系统调用的封装,可以在Windows或者Linux系统中使用
系统调用:是Linux内核中的函数接口,只能在Linux系统中使用
5.Linux系统中时间的获取:
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};