This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] copy_file_range: New function to copy file data


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."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]