From 3c470803d08477dab9c7faada29a5f4c59dd519e Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Sun, 10 Jan 2016 21:46:45 -0500
Subject: [PATCH] fdio: Export loop_write

I plan to use this in rpm-ostree.  Sad how many times this gets
reinvented.  Should probably stick a copy in `glib-unix.h` or so.
---
 glnx-fdio.c | 6 +++---
 glnx-fdio.h | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/glnx-fdio.c b/glnx-fdio.c
index 7db33c4c6..466cbc4e8 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -354,7 +354,7 @@ static int btrfs_reflink(int infd, int outfd) {
         return 0;
 }
 
-static int loop_write(int fd, const void *buf, size_t nbytes) {
+int glnx_loop_write(int fd, const void *buf, size_t nbytes) {
         const uint8_t *p = buf;
 
         g_return_val_if_fail(fd >= 0, -1);
@@ -437,7 +437,7 @@ static int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
                         if (n == 0) /* EOF */
                                 break;
 
-                        r = loop_write(fdt, buf, (size_t) n);
+                        r = glnx_loop_write(fdt, buf, (size_t) n);
                         if (r < 0)
                                 return r;
                 }
@@ -685,7 +685,7 @@ glnx_file_replace_contents_with_perms_at (int                   dfd,
       goto out;
     }
 
-  if ((r = loop_write (fd, buf, len)) != 0)
+  if ((r = glnx_loop_write (fd, buf, len)) != 0)
     {
       errno = -r;
       glnx_set_error_from_errno (error);
diff --git a/glnx-fdio.h b/glnx-fdio.h
index a90544a9d..c0fd4e483 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -102,6 +102,9 @@ glnx_readlinkat_malloc (int            dfd,
                         GCancellable  *cancellable,
                         GError       **error);
 
+int
+glnx_loop_write (int fd, const void *buf, size_t nbytes);
+
 typedef enum {
   GLNX_FILE_COPY_OVERWRITE,
   GLNX_FILE_COPY_NOXATTRS,
-- 
GitLab