Skip to content

Instantly share code, notes, and snippets.

@NoahDragon
Last active February 3, 2016 21:51
Show Gist options
  • Save NoahDragon/758b69871a48eef3d13b to your computer and use it in GitHub Desktop.
Save NoahDragon/758b69871a48eef3d13b to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment