]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Prefer idx_t to size_t in system.c
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
* src/buffer.c (_flush_write): Return idx_t, not ssize_t,
to accommodate system.c changes.  All uses changed.
(_gnu_flush_write): Output correct errno value after write error.
Simplify multi-volume mode.
* src/system.c (sys_write_archive_buffer)
(sys_child_open_for_compress, sys_exec_setmtime_script):
Prefer idx_t to size_t.

src/buffer.c
src/common.h
src/system.c

index 4f5e4faac44f0c94da03fa0c3363ef2e9c6f5220..108a4a6876c5eb78b0046e52a1ea193a9acc5926 100644 (file)
@@ -872,10 +872,10 @@ _open_archive (enum access_mode wanted_access)
 }
 
 /* Perform a write to flush the buffer.  */
-static ssize_t
+static idx_t
 _flush_write (void)
 {
-  ssize_t status;
+  idx_t status;
 
   checkpoint_run (true);
   if (tape_length_option && tape_length_option <= bytes_written)
@@ -1826,9 +1826,7 @@ simple_flush_read (void)
 static void
 simple_flush_write (MAYBE_UNUSED idx_t level)
 {
-  ssize_t status;
-
-  status = _flush_write ();
+  idx_t status = _flush_write ();
   if (status != record_size)
     archive_write_error (status);
   else
@@ -1895,22 +1893,15 @@ gnu_flush_read (void)
 static void
 _gnu_flush_write (idx_t buffer_level)
 {
-  ssize_t status;
   union block *header;
   char *copy_ptr;
   idx_t copy_size;
   idx_t bufsize;
   struct bufmap *map;
 
-  status = _flush_write ();
-  if (status != record_size && !multi_volume_option)
-    archive_write_error (status);
-  else
-    {
-      if (status)
-        records_written++;
-      bytes_written += status;
-    }
+  idx_t status = _flush_write ();
+  records_written += !!status;
+  bytes_written += status;
 
   if (status == record_size)
     {
@@ -1921,15 +1912,19 @@ _gnu_flush_write (idx_t buffer_level)
 
   if (status % BLOCKSIZE)
     {
+      int e = errno;
       paxerror (0, _("write did not end on a block boundary"));
+      errno = e;
       archive_write_error (status);
     }
 
-  /* In multi-volume mode. */
   /* ENXIO is for the UNIX PC.  */
-  if (status < 0 && errno != ENOSPC && errno != EIO && errno != ENXIO)
+  if (! (multi_volume_option
+        && (errno == ENOSPC || errno == EIO || errno == ENXIO)))
     archive_write_error (status);
 
+  /* In multi-volume mode.  */
+
   if (!new_volume (ACCESS_WRITE))
     return;
 
index 5680f4df26cf3392c02c678bedb66359452c3750..2175129541e2747f0ce81be80fde1c32600540ee 100644 (file)
@@ -928,7 +928,7 @@ bool sys_compare_links (struct stat *link_data, struct stat *stat_data);
 int sys_truncate (int fd);
 pid_t sys_child_open_for_compress (void);
 pid_t sys_child_open_for_uncompress (void);
-size_t sys_write_archive_buffer (void);
+idx_t sys_write_archive_buffer (void);
 bool sys_get_archive_stat (void);
 int sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st);
 void sys_wait_command (void);
index e2fe1e268711237b454eb683b1cc64db8825099d..7bebd355b055bf7fa2e79ca3795effdcb9982f5f 100644 (file)
@@ -137,7 +137,7 @@ sys_truncate (int fd)
   return write (fd, "", 0);
 }
 
-size_t
+idx_t
 sys_write_archive_buffer (void)
 {
   return full_write (archive, record_start->buffer, record_size);
@@ -306,7 +306,7 @@ is_regular_file (const char *name)
     return errno == ENOENT;
 }
 
-size_t
+idx_t
 sys_write_archive_buffer (void)
 {
   return rmtwrite (archive, record_start->buffer, record_size);
@@ -462,7 +462,7 @@ sys_child_open_for_compress (void)
           length < record_size;
           length += status, cursor += status)
        {
-         size_t size = record_size - length;
+         idx_t size = record_size - length;
 
          status = safe_read (STDIN_FILENO, cursor, size);
          if (status < 0)
@@ -935,8 +935,8 @@ sys_exec_setmtime_script (const char *script_name,
   struct pollfd pfd;
 
   char *buffer = NULL;
-  size_t buflen = 0;
-  size_t bufsize = 0;
+  idx_t buflen = 0;
+  idx_t bufsize = 0;
   char *cp;
   int rc = 0;
 
@@ -968,6 +968,8 @@ sys_exec_setmtime_script (const char *script_name,
        open_error (dev_null);
 
       priv_set_restore_linkdir ();
+      /* FIXME: This mishandles shell metacharacters in the file name.
+        Come to think of it, isn't every use of xexec suspect?  */
       xexec (command);
     }
   close (p[1]);
@@ -992,11 +994,7 @@ sys_exec_setmtime_script (const char *script_name,
       if (pfd.revents & POLLIN)
        {
          if (buflen == bufsize)
-           {
-             if (bufsize == 0)
-               bufsize = BUFSIZ;
-             buffer = x2nrealloc (buffer, &bufsize, 1);
-           }
+           buffer = xpalloc (buffer, &bufsize, 1, -1, 1);
          ssize_t nread = read (pfd.fd, buffer + buflen, bufsize - buflen);
          if (nread < 0)
            {
@@ -1036,7 +1034,7 @@ sys_exec_setmtime_script (const char *script_name,
   else
     {
       if (buflen == bufsize)
-       buffer = x2nrealloc (buffer, &bufsize, 1);
+       buffer = xirealloc (buffer, ++bufsize);
       buffer[buflen] = 0;
     }