[PATCH v6 1/1] ldconfig: add --install option
Andreas Schwab
schwab@linux-m68k.org
Tue Jun 23 20:58:05 GMT 2026
On Jun 23 2026, Adhemerval Zanella Netto wrote:
>> + /* At this point, sz contains the number of bytes copied so far.
>> + Copy the rest of the file. */
>> + while ((r = read (src_fd, buf, sizeof(buf))) > 0)
>> + {
>> + bp = buf;
>> + while (r > 0 && (w = write (dest_fd, bp, r)) > 0)
>> + {
>> + bp += w;
>> + r -= w;
>> + sz += w;
>> + }
>> + if (w <= 0)
>> + break;
>> + }
>> + if (r < 0)
>> + {
>> + unlink (dest);
>> + close (dest_fd);
>> + error (EXIT_FAILURE, errno, _("Error reading file %s"), source);
>> + }
>> + if (w < 0)
>> + {
>> + unlink (dest);
>> + close (dest_fd);
>> + error (EXIT_FAILURE, errno, _("Error writing file %s"), dest);
>> + }
>> +
>> + close (src_fd);
>> +
>> + /* Make sure we copied it all. */
>> + if (sz < st.st_size)
>> + {
>> + unlink (dest);
>> + close (dest_fd);
>> + error (EXIT_FAILURE, errno, _("Unable to copy file %s to %s"),
>> + source, dest);
>
> This might use stale error from possible unlink/close. I would recommend save and
> used the saved value in the error() call.
If r == 0 then errno isn't set at all.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
More information about the Libc-alpha
mailing list