NoahDragon
7/25/2014 - 1:53 PM

Reading all the bytes from file-- from book "Linux System Programming"

Reading all the bytes from file-- from book "Linux System Programming"

/*
Snippet from: Linux System Programming
Purpose: read file to avoid system interuption
Relative: Nonblocking reads
*/

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;
}