summaryrefslogtreecommitdiffstats
path: root/usr/kinit/xpio.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:06:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:06:04 +0000
commit2f0649f6fe411d7e07c8d56cf8ea56db53536da8 (patch)
tree778611fb52176dce1ad06c68e87b2cb348ca0f7b /usr/kinit/xpio.c
parentInitial commit. (diff)
downloadklibc-2f0649f6fe411d7e07c8d56cf8ea56db53536da8.tar.xz
klibc-2f0649f6fe411d7e07c8d56cf8ea56db53536da8.zip
Adding upstream version 2.0.13.upstream/2.0.13upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'usr/kinit/xpio.c')
-rw-r--r--usr/kinit/xpio.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/usr/kinit/xpio.c b/usr/kinit/xpio.c
new file mode 100644
index 0000000..42a9844
--- /dev/null
+++ b/usr/kinit/xpio.c
@@ -0,0 +1,51 @@
+/*
+ * Looping versions of pread() and pwrite()
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "xpio.h"
+
+ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
+{
+ ssize_t ctr = 0;
+ ssize_t rv = 0;
+ char *bp = buf;
+
+ while (count) {
+ rv = pread(fd, bp, count, offset);
+
+ if (rv == 0 || (rv == -1 && errno != EINTR))
+ break;
+
+ bp += rv;
+ count -= rv;
+ offset += rv;
+ ctr += rv;
+ }
+
+ return ctr ? ctr : rv;
+}
+
+ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset)
+{
+ ssize_t ctr = 0;
+ ssize_t rv = 0;
+ char *bp = buf;
+
+ while (count) {
+ rv = pwrite(fd, bp, count, offset);
+
+ if (rv == 0 || (rv == -1 && errno != EINTR))
+ break;
+
+ bp += rv;
+ count -= rv;
+ offset += rv;
+ ctr += rv;
+ }
+
+ return ctr ? ctr : rv;
+}