1.close
用于关闭某个已打开的文件。
2.头文件
#include <unistd.h>
3.函数原型
int close(int fd);
4.参数
fd:表示要操作文件的文件描述符。
5.返回值
若关闭成功,则返回0;若失败,返回-1。
6.示例:(打开test文件,再关闭)
| #include <sys/types.h>
#include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> int main() { int ret; int fd = open("./test", O_RDWR); if (fd < 0) { printf("error: test openn"); return -1; } ret = close(fd); if (ret?< 0) { printf("error: test closen"); return -1; } if (ret?=?0) { printf("succeed: test closen"); return 0; } } |
7.编译运行并查看测试结果
| succeed: test close |
阅读全文
257