diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2025-08-08 08:45:59 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2025-09-15 23:17:35 -0700 |
| commit | f6bffa431dfbb313b39173433a8f12e45391ecce (patch) | |
| tree | 3e8200b0457b2087e74b2197965caaac896eab59 | |
| parent | cp: prefer signed types in copy-file-data.c (diff) | |
| download | coreutils-f6bffa431dfbb313b39173433a8f12e45391ecce.tar.gz coreutils-f6bffa431dfbb313b39173433a8f12e45391ecce.zip | |
cp: create_hole now returns off_t
* src/copy-file-data.c (create_hole): Refactor by returning
resulting offset, not bool. All callers changed.
| -rw-r--r-- | src/copy-file-data.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/copy-file-data.c b/src/copy-file-data.c index 9c551e149..dba14d954 100644 --- a/src/copy-file-data.c +++ b/src/copy-file-data.c @@ -59,8 +59,9 @@ punch_hole (int fd, off_t offset, off_t length) /* Create a hole at the end of the file with descriptor FD and name NAME. The hole is of size SIZE. Assume FD is already at file end, - and advance FD past the newly-created hole. */ -static bool + and advance FD past the newly-created hole. + Return the resulting position, or -1 on failure. */ +static off_t create_hole (int fd, char const *name, off_t size) { off_t file_end = lseek (fd, size, SEEK_CUR); @@ -68,7 +69,7 @@ create_hole (int fd, char const *name, off_t size) if (file_end < 0) { error (0, errno, _("cannot lseek %s"), quoteaf (name)); - return false; + return -1; } /* Some file systems (like XFS) preallocate when write extending a file. @@ -78,10 +79,10 @@ create_hole (int fd, char const *name, off_t size) if (punch_hole (fd, file_end - size, size) < 0) { error (0, errno, _("error deallocating %s"), quoteaf (name)); - return false; + return -1; } - return true; + return file_end; } /* Similarly, whether ERR indicates that the copying operation is not @@ -227,7 +228,7 @@ sparse_copy (int src_fd, int dest_fd, char **abuf, idx_t buf_size, psize += csize; else if (prev_hole) { - if (! create_hole (dest_fd, dst_name, psize)) + if (create_hole (dest_fd, dst_name, psize) < 0) return false; pbuf = cbuf; psize = csize; @@ -379,8 +380,9 @@ lseek_copy (int src_fd, int dest_fd, char **abuf, idx_t buf_size, *hole_size += ext_hole_size; else if (sparse_mode != SPARSE_NEVER) { - if (! create_hole (dest_fd, dst_name, ext_hole_size)) - return -1; + off_t epos = create_hole (dest_fd, dst_name, ext_hole_size); + if (epos < 0) + return epos; } else { |
