summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2023-03-11 18:24:13 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2023-03-11 18:24:13 +0100
commit980784c1917f19bfd2e9b11faca76d14e8589daa (patch)
treec9b3988642585cd50af5ec1ffad75331886c0aa4 /src/io.c
parentbfef0924f58eab930bdd826ac0132786abc32220 (diff)
New upstream version 4.12upstream/4.12
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/io.c b/src/io.c
index 720a9c5..a6c0a68 100644
--- a/src/io.c
+++ b/src/io.c
@@ -11,6 +11,7 @@
# include "config.h"
#endif
#include <sys/stat.h>
+#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -594,39 +595,37 @@ EXPORT_SYMBOL int HX_rrmdir(const char *dir)
EXPORT_SYMBOL ssize_t HXio_fullread(int fd, void *vbuf, size_t size)
{
char *buf = vbuf;
- size_t done = 0;
if (size > SSIZE_MAX)
size = SSIZE_MAX;
- while (done < size) {
- ssize_t ret = read(fd, buf, size - done);
+ while (size > 0) {
+ ssize_t ret = read(fd, buf, size);
if (ret < 0)
return ret;
else if (ret == 0)
break;
- done += ret;
buf += ret;
+ size -= ret;
}
- return done;
+ return buf - static_cast(char *, vbuf);
}
EXPORT_SYMBOL ssize_t HXio_fullwrite(int fd, const void *vbuf, size_t size)
{
const char *buf = vbuf;
- size_t done = 0;
if (size > SSIZE_MAX)
size = SSIZE_MAX;
- while (done < size) {
- ssize_t ret = write(fd, buf, size - done);
+ while (size > 0) {
+ ssize_t ret = write(fd, buf, size);
if (ret < 0)
return ret;
else if (ret == 0)
break;
- done += ret;
buf += ret;
+ size -= ret;
}
- return done;
+ return buf - static_cast(const char *, vbuf);
}
#if __linux__