Created
April 11, 2017 19:10
-
-
Save max-dark/ec4c044e8ee4303300c91eb9436635e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
//... | |
ssize_t buf_size = ...; | |
char * buffer = (char *) malloc(buf_size); | |
//.... | |
ssize_t read_count = 0; | |
int file_in; | |
file_in = open(...); | |
int at_eof = 0; | |
while (!at_eof) { | |
read_count = read(file_in, buffer, buf_size); | |
switch(read_count) { | |
// eof | |
case 00: at_eof = 1; break; | |
// read error | |
case -1: { | |
switch(errno) { | |
// no data, retry read | |
case EINTR: case EAGAIN:break; | |
// fatal errors | |
default: | |
perror("read "); | |
abort(); | |
break; | |
} | |
} | |
break; | |
// have some data - process it | |
default: { | |
// ... | |
at_eof = read_count != buf_size; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment