diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Read and write slot keys and pages in full
xread and xwrite may move fewer bytes than asked. A short write of the key left a slot that could never match, a short read of it reported a collision, and a page write that moved nothing looped for ever.
Diffstat (limited to 'source/cache.c')
-rw-r--r--source/cache.c4
1 file changed, 2 insertions, 2 deletions
diff --git a/source/cache.c b/source/cache.c
index 60e071b..af391db 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -85,7 +85,7 @@ static int open_slot(struct cache_slot *slot)
if (fstat(slot->cache_fd, &slot->st))
return errno;
- slot->buflen = xread(slot->cache_fd, slot->buf, sizeof(slot->buf));
+ slot->buflen = read_in_full(slot->cache_fd, slot->buf, sizeof(slot->buf));
if (slot->buflen < 0)
return errno;
@@ -265,7 +265,7 @@ static int lock_slot(struct cache_slot *slot)
// start from empty now that nobody else can be writing it.
if (ftruncate(slot->lock_fd, 0) < 0)
return errno;
- if (xwrite(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
+ if (write_in_full(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
return errno;
return 0;
}