Adjust better to Gnulib signed-int read changes

The 2024-08-09 Gnulib changes that caused some modules prefer
signed types to size_t means that Tar should follow suit.
* src/buffer.c (short_read):
* src/system.c (sys_child_open_for_compress)
(sys_child_open_for_uncompress):
rmtread and safe_read return ptrdiff_t not idx_t;
don’t rely on implementation defined conversion.
* src/misc.c (blocking_read): Never return a negative number.
Return idx_t, not ptrdiff_t, with the same convention for EOF
and error as the new full_read.  All callers changed.
* src/sparse.c (sparse_dump_region, check_sparse_region)
(check_data_region):
* src/update.c (append_file):
full_read no longer returns SAFE_READ_ERROR for I/O error; instead it
returns the number of bytes successfully read, and sets errno.
Adjust to this.
* src/system.c (sys_child_open_for_uncompress):
Rewrite to avoid need for goto and label.
This commit is contained in:
Paul Eggert
2024-11-01 23:47:23 -07:00
parent e513950080
commit 7c0feaefd0
8 changed files with 87 additions and 134 deletions
+11 -7
View File
@@ -841,25 +841,29 @@ deref_stat (char const *name, struct stat *buf)
/* Read from FD into the buffer BUF with COUNT bytes. Attempt to fill
BUF. Wait until input is available; this matters because files are
opened O_NONBLOCK for security reasons, and on some file systems
this can cause read to fail with errno == EAGAIN. Return the
actual number of bytes read, zero for EOF, or
-1 upon error. */
ptrdiff_t
this can cause read to fail with errno == EAGAIN.
If returning less than COUNT, set errno to indicate the error
except set errno = 0 to indicate EOF. */
idx_t
blocking_read (int fd, void *buf, idx_t count)
{
idx_t bytes = full_read (fd, buf, count);
#if defined F_SETFL && O_NONBLOCK
if (bytes == SAFE_READ_ERROR && errno == EAGAIN)
if (bytes < count && errno == EAGAIN)
{
int flags = fcntl (fd, F_GETFL);
if (0 <= flags && flags & O_NONBLOCK
&& fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
bytes = full_read (fd, buf, count);
{
char *cbuf = buf;
count -= bytes;
bytes += full_read (fd, cbuf + bytes, count);
}
}
#endif
return bytes == SAFE_READ_ERROR || (bytes == 0 && errno != 0) ? -1 : bytes;
return bytes;
}
/* Write to FD from the buffer BUF with COUNT bytes. Do a full write.