X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fio.c;h=999922b12e517c63be16ce1b20d7d22d077f9acc;hp=3a261a4053ec9fb369077664c66c88ed69e484b8;hb=6dbbfabca414018b4c5acb3e6e597d84e2b19caf;hpb=1ac26f37368b33e0952e19df05184776c80159c8;ds=sidebyside diff --git a/ccan/tdb2/io.c b/ccan/tdb2/io.c index 3a261a40..999922b1 100644 --- a/ccan/tdb2/io.c +++ b/ccan/tdb2/io.c @@ -225,44 +225,6 @@ bool tdb_pwrite_all(int fd, const void *buf, size_t len, tdb_off_t off) return true; } -/* Even on files, we can get partial reads due to signals. */ -bool tdb_pread_all(int fd, void *buf, size_t len, tdb_off_t off) -{ - while (len) { - ssize_t ret; - ret = pread(fd, buf, len, off); - if (ret < 0) - return false; - if (ret == 0) { - /* ETOOSHORT? */ - errno = EWOULDBLOCK; - return false; - } - buf = (char *)buf + ret; - off += ret; - len -= ret; - } - return true; -} - -bool tdb_read_all(int fd, void *buf, size_t len) -{ - while (len) { - ssize_t ret; - ret = read(fd, buf, len); - if (ret < 0) - return false; - if (ret == 0) { - /* ETOOSHORT? */ - errno = EWOULDBLOCK; - return false; - } - buf = (char *)buf + ret; - len -= ret; - } - return true; -} - /* write a lump of data at a specified offset */ static int tdb_write(struct tdb_context *tdb, tdb_off_t off, const void *buf, tdb_len_t len) @@ -305,13 +267,14 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf, if (tdb->map_ptr) { memcpy(buf, off + (char *)tdb->map_ptr, len); } else { - if (!tdb_pread_all(tdb->fd, buf, len, off)) { + ssize_t r = pread(tdb->fd, buf, len, off); + if (r != len) { tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL, - "tdb_read failed at %zu " + "tdb_read failed with %zi at %zu " "len=%zu (%s) map_size=%zu", - (size_t)off, (size_t)len, - strerror(errno), - (size_t)tdb->map_size); + r, (size_t)off, (size_t)len, + strerror(errno), + (size_t)tdb->map_size); return -1; } }