此类函数定义在头文件:#include <unistd.h>
一、read使用示例:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
int read_fd, size;
char buffer[1024] = "\0";
read_fd = open("in.txt", O_RDONLY,S_IRUSR);
if (-1 == read_fd) // 打开文件失败,则异常返回
{
return -1;
}
size = read(read_fd, buffer, 1024);
printf("read_size %d:%s\n", size, buffer);
close(read_fd);
return 0;
}
输入文件:
执行输出: