随笔分类 -  文件IO

摘要:定义 函数声明 flock结构体 建议锁 强制锁 实例 #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <sys/file.h> void lock_set(int fd, 阅读全文
posted @ 2022-04-30 20:07 starc的miao 阅读(51) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> int main(void) { struct stat st; if (-1 == stat("./log.txt", &st)) { perror("error:"); ex 阅读全文
posted @ 2022-04-30 14:25 starc的miao 阅读(47) 评论(0) 推荐(0)
摘要:lseek文件偏移量 lseek()不适用于所有类型的文件,不允许应用于lseek()应用于管道、FIFO、socket或者终端 文件空洞 /*拷贝多份文件*/ #include <stdio.h> #include <fcntl.h> // open #include <string.h> #in 阅读全文
posted @ 2022-04-30 13:26 starc的miao 阅读(49) 评论(0) 推荐(0)
摘要:putchar 把参数 char 指定的字符(一个无符号字符)写入到标准输出 stdout 中。 返回值:该函数以无符号 char 强制转换为 int 的形式返回写入的字符,如果发生错误则返回 EOF。 int putchar(int char) #include <stdio.h> int mai 阅读全文
posted @ 2022-04-29 17:10 starc的miao 阅读(63) 评论(0) 推荐(0)
摘要:read 代码习惯 常见错误码 #include <stdio.h> #include <fcntl.h> // open #include <stdlib.h> // exit #include <unistd.h> // close\read // #include <sys/types.h> 阅读全文
posted @ 2022-04-29 16:43 starc的miao 阅读(42) 评论(0) 推荐(0)
摘要:文件描述符 定义 fileno 将文件指针转化为文件描述符 fdopen 将文件描述符转化为文件指针 打开或者关闭文件 <fcntl.h> open <sys/stat.h>:mode_t mode <fcntl.h>:int flags fail return: -1 flag mode <sys 阅读全文
posted @ 2022-04-28 22:06 starc的miao 阅读(71) 评论(0) 推荐(0)