[LibOS] Fix read/write return check in FS tests

This commit is contained in:
Rafał Wojdyła
2020-04-14 01:36:32 +02:00
committed by Michał Kowalczyk
parent 9542cc8e90
commit 4658dfc2bf
+7 -2
View File
@@ -32,11 +32,16 @@ void read_fd(const char* path, int fd, void* buffer, size_t size) {
ssize_t ret = read(fd, buffer + offset, size);
if (ret == -EINTR)
continue;
if (ret <= 0)
if (ret < 0)
fatal_error("Failed to read file %s: %s\n", path, strerror(errno));
if (ret == 0)
break;
size -= ret;
offset += ret;
}
if (size != 0)
fatal_error("Failed to read file %s: EOF\n", path);
}
void seek_fd(const char* path, int fd, ssize_t offset, int mode) {
@@ -65,7 +70,7 @@ void write_fd(const char* path, int fd, const void* buffer, size_t size) {
ssize_t ret = write(fd, buffer + offset, size);
if (ret == -EINTR)
continue;
if (ret <= 0)
if (ret < 0)
fatal_error("Failed to write file %s: %s\n", path, strerror(errno));
size -= ret;
offset += ret;