This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] copy_file_range: New function to copy file data
- From: Andreas Schwab <schwab at suse dot de>
- To: fweimer at redhat dot com (Florian Weimer)
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 23 Nov 2017 16:13:21 +0100
- Subject: Re: [PATCH] copy_file_range: New function to copy file data
- Authentication-results: sourceware.org; auth=none
- References: <20171117145604.655D24469B999@oldenburg.str.redhat.com>
On Nov 17 2017, fweimer@redhat.com (Florian Weimer) wrote:
> +COPY_FILE_RANGE_DECL
> +ssize_t
> +COPY_FILE_RANGE (int infd, __off64_t *pinoff,
> + int outfd, __off64_t *poutoff,
> + size_t length, unsigned int flags)
> +{
> + if (flags != 0)
> + {
> + __set_errno (EINVAL);
> + return -1;
> + }
> +
> + struct stat64 instat;
> + struct stat64 outstat;
> + if (fstat64 (infd, &instat) != 0 || fstat64 (outfd, &outstat))
!= 0
> + /* Write the buffer part which was read to the destination. */
> + char *end = buf + read_count;
> + for (char *p = buf; p < end; )
> + {
> + ssize_t write_count;
> + if (poutoff == NULL)
> + write_count = write (outfd, p, end - p);
> + else
> + write_count = __libc_pwrite64 (outfd, p, end - p, *poutoff);
> + if (write_count == 0)
> + {
> + /* Assume that this means no space on the target file
> + system, and use the error handling path below. */
I don't think write can ever return 0 when writing more than zero bytes.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."