Use full-read instead of safe-read

This helps handle archiving on certain filesystems where read()
returns less bytes than requested when reading from a regular
file.

References:

  https://savannah.gnu.org/bugs/index.php?64426
  https://lists.gnu.org/archive/html/bug-tar/2021-07/msg00001.html

* gnulib.modules: Add full-read.
* src/common.h: Include full-read.h
* src/misc.c: Use full_read.
* src/sparse.c: Likewise.
* src/update.c: Likewise.
This commit is contained in:
Sergey Poznyakoff
2023-07-17 17:07:12 +03:00
parent 31f68bbe2a
commit e7a5e12445
5 changed files with 60 additions and 29 deletions
+4 -2
View File
@@ -821,7 +821,7 @@ deref_stat (char const *name, struct stat *buf)
size_t
blocking_read (int fd, void *buf, size_t count)
{
size_t bytes = safe_read (fd, buf, count);
size_t bytes = full_read (fd, buf, count);
#if defined F_SETFL && O_NONBLOCK
if (bytes == SAFE_READ_ERROR && errno == EAGAIN)
@@ -829,10 +829,12 @@ blocking_read (int fd, void *buf, size_t count)
int flags = fcntl (fd, F_GETFL);
if (0 <= flags && flags & O_NONBLOCK
&& fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
bytes = safe_read (fd, buf, count);
bytes = full_read (fd, buf, count);
}
#endif
if (bytes == 0 && errno != 0)
bytes = SAFE_READ_ERROR;
return bytes;
}