summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2022-08-01 15:27:34 +0000
committerColin Walters <walters@verbum.org>2022-08-01 15:27:34 +0000
commit26375b5308360764bc6604f292192b88a59ad3ce (patch)
tree0bcc43019db4d0d7b3214a02862c2c5b5bdb5653
parentc59eb271b5127309c73117bbc871dcfd9fd159a6 (diff)
parent7a2f26a312c92e335652962bb99bf2e160720c8d (diff)
downloadlibglnx-26375b5308360764bc6604f292192b88a59ad3ce.tar.gz
Merge branch 'pr/ficlone-fixes' into 'master'
fdio: fix fd offset handling with `FICLONE` See merge request GNOME/libglnx!41
-rw-r--r--glnx-fdio.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index ee69aa1..b1af679 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -794,10 +794,21 @@ glnx_regfile_copy_bytes (int fdf, int fdt, off_t max_bytes)
/* If we've requested to copy the whole range, try a full-file clone first.
*/
- if (max_bytes == (off_t) -1)
+ if (max_bytes == (off_t) -1 &&
+ lseek (fdf, 0, SEEK_CUR) == 0 &&
+ lseek (fdt, 0, SEEK_CUR) == 0)
{
if (ioctl (fdt, FICLONE, fdf) == 0)
- return 0;
+ {
+ /* All the other methods advance the fds. Do it here too for consistency. */
+ if (lseek (fdf, 0, SEEK_END) < 0)
+ return -1;
+ if (lseek (fdt, 0, SEEK_END) < 0)
+ return -1;
+
+ return 0;
+ }
+
/* Fall through */
struct stat stbuf;