Reset errno values where read
According to `man 3 errno`: ``` The value of errno is never set to zero by any system call or library function. ``` So we must set it to 0 ourselves before each `read` and `write` call to ensure we don't get stuck in an error loop.
This commit is contained in:
committed by
Travis Geiselbrecht
parent
4dd3bbd2f1
commit
00b6ca080e
@@ -96,6 +96,7 @@ static int writex(int fd, void *data, size_t len) {
|
|||||||
int r;
|
int r;
|
||||||
char *x = data;
|
char *x = data;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
errno = NO_ERROR;
|
||||||
r = write(fd, x, len);
|
r = write(fd, x, len);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
@@ -162,6 +163,7 @@ static void *load_file(const char *fn, size_t *len) {
|
|||||||
*len = sz;
|
*len = sz;
|
||||||
}
|
}
|
||||||
while (sz > 0) {
|
while (sz > 0) {
|
||||||
|
errno = NO_ERROR;
|
||||||
r = read(fd, x, sz);
|
r = read(fd, x, sz);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ static int readx(int s, void *_data, int len) {
|
|||||||
char *data = _data;
|
char *data = _data;
|
||||||
int r;
|
int r;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
errno = NO_ERROR;
|
||||||
r = read(s, data, len);
|
r = read(s, data, len);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
fprintf(stderr, "error: eof during socket read\n");
|
fprintf(stderr, "error: eof during socket read\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user