Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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