X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/0eb74c284927b79b607adceae7262734e81a46b3..fa7c556d251ebcb41ef9709b4d85a2c820dee94b:/src/fops.c diff --git a/src/fops.c b/src/fops.c index 746455f..e546b10 100644 --- a/src/fops.c +++ b/src/fops.c @@ -17,19 +17,28 @@ * along with this program. If not, see . */ #include +#include #include "misc.h" +#include "error.h" #include "lbx.h" /* Default I/O operations for ordinary files. */ static size_t file_read(void *buf, size_t size, void *handle) { - return fread(buf, 1, size, (FILE *)handle); + size_t rc = fread(buf, 1, size, (FILE *)handle); + + if (rc < size && ferror((FILE *)handle)) + lbx_error_raise(-errno); + return rc; } static int file_seek(void *handle, long offset, int whence) { - return fseek((FILE *)handle, offset, whence); + if (fseek((FILE *)handle, offset, whence) == -1) { + lbx_error_raise(-errno); + return -1; + } } static long file_tell(void *handle) @@ -55,7 +64,7 @@ static size_t pipe_read(void *buf, size_t size, void *handle) struct lbx_pipe_state *state = handle; size_t rc; - rc = fread(buf, 1, size, state->f); + rc = file_read(buf, size, state->f); state->offset += rc; return rc; }