Improve handling of incomplete reads
a failure with EAGAIN should be tried again (though a timeout / select would be appropriate?); a success with zero bytes read or written is treated as a failure (is this correct?)
This commit is contained in:
parent
08afc2c2f3
commit
1a4cfe99de
1 changed files with 5 additions and 0 deletions
5
ungeli.c
5
ungeli.c
|
|
@ -40,6 +40,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define IVSIZE (16)
|
||||
#define SHA512_MDLEN (SHA512_DIGEST_LENGTH)
|
||||
|
|
@ -136,6 +137,8 @@ static void
|
|||
read_full(int fd, unsigned char *blk, int blocksize) {
|
||||
do {
|
||||
int res = read(fd, blk, blocksize);
|
||||
if(res == 0) fatal("read_full read() -> 0");
|
||||
if(res < 0 && errno == EAGAIN) continue;
|
||||
if(res < 0) perror_fatal("read_full");
|
||||
blk += res;
|
||||
blocksize -= res;
|
||||
|
|
@ -146,6 +149,8 @@ static void
|
|||
write_full(int fd, const unsigned char *blk, int blocksize) {
|
||||
do {
|
||||
int res = write(fd, blk, blocksize);
|
||||
if(res == 0) fatal("write_full write() -> 0");
|
||||
if(res < 0 && errno == EAGAIN) continue;
|
||||
if(res < 0) perror_fatal("write_full");
|
||||
blk += res;
|
||||
blocksize -= res;
|
||||
|
|
|
|||
Loading…
Reference in a new issue