These handle EINTR and make sure the amount requested is read into the
buffer.

Signed-off-by: Derek Foreman <der...@osg.samsung.com>
---
 src/wayland-os.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/wayland-os.h |  6 ++++++
 2 files changed, 44 insertions(+)

diff --git a/src/wayland-os.c b/src/wayland-os.c
index 2cd6bf3..4c6ffa7 100644
--- a/src/wayland-os.c
+++ b/src/wayland-os.c
@@ -267,3 +267,41 @@ wl_os_create_anonymous_file(off_t size)
 
        return fd;
 }
+
+int wl_os_write(int fd, void *buffer, int count)
+{
+       int ret;
+       int total = count;
+
+       while (count > 0) {
+               ret = write(fd, buffer, count);
+               if (ret == -1 && errno == EINTR)
+                       continue;
+
+               if (ret == -1)
+                       return -1;
+
+               count -= ret;
+               buffer += ret;
+       }
+       return total;
+}
+
+int wl_os_read(int fd, void *buffer, int count)
+{
+       int ret;
+       int total = count;
+
+       while (count > 0) {
+               ret = read(fd, buffer, count);
+               if (ret == -1 && errno == EINTR)
+                       continue;
+
+               if (ret == -1)
+                       return -1;
+
+               count -= ret;
+               buffer += ret;
+       }
+       return total;
+}
diff --git a/src/wayland-os.h b/src/wayland-os.h
index 300a343..9679214 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -52,6 +52,12 @@ wl_os_resize_file(int fd, off_t size);
 int
 wl_os_create_anonymous_file(off_t size);
 
+int
+wl_os_write(int fd, void *buffer, int count);
+
+int
+wl_os_read(int fd, void *buffer, int count);
+
 /*
  * The following are for wayland-os.c and the unit tests.
  * Do not use them elsewhere.
-- 
2.7.0

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to