Bloody perror messes with errno; need to save errno.

This commit is contained in:
Rafal Wojtczuk 2011-03-16 16:24:54 +01:00
parent d40fb3a2e1
commit e410ad52ba

View File

@ -25,6 +25,14 @@
#include <fcntl.h>
#include <errno.h>
void perror_wrapper(char * msg)
{
int prev=errno;
perror(msg);
errno=prev;
}
int write_all(int fd, void *buf, int size)
{
int written = 0;
@ -34,7 +42,7 @@ int write_all(int fd, void *buf, int size)
if (ret == -1 && errno == EINTR)
continue;
if (ret <= 0) {
perror("write");
perror_wrapper("write");
return 0;
}
written += ret;
@ -57,7 +65,7 @@ int read_all(int fd, void *buf, int size)
return 0;
}
if (ret < 0) {
perror("read");
perror_wrapper("read");
return 0;
}
got_read += ret;
@ -77,11 +85,11 @@ int copy_fd_all(int fdout, int fdin)
if (!ret)
break;
if (ret < 0) {
perror("read");
perror_wrapper("read");
return 0;
}
if (!write_all(fdout, buf, ret)) {
perror("write");
perror_wrapper("write");
return 0;
}
}