linux read
ssize_t ret;
while(len !=0 && (ret = read (fd , buf , len ))!=0)
{
if(ret == -1)
{
if(errno == EINTR)
continue;
perror("read");
break;
}
len-=ret;
buf+=ret;
{
if(ret == -1)
{
if(errno == EINTR)
continue;
perror("read");
break;
}
len-=ret;
buf+=ret;
}
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
int
main (int argc, char *argv[])
{
int fd = open ("read.c", O_RDWR);
char buff[1024];
bzero(buff,sizeof(buff));
char *buf = buff;
int len = sizeof(buff);
ssize_t ret = 0;
while (len != 0 && (ret = read (fd, buf, len)) != 0)
{
if (ret == -1)
{
if (errno == EINTR)
continue;
perror ("read");
break;
}
printf ("%s", buf);
len -= ret;
buf += ret;
}
close (fd);
return 0;
}