]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Be a bit more consistent about comparing to zero
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 20:44:33 +0000 (13:44 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
* src/buffer.c (xclose, archive_is_dev, close_archive)
(write_fatal_details, init_volume_number)
(closeout_volume_number, new_volume, try_new_volume):
* src/checkpoint.c (format_checkpoint_string):
* src/compare.c (process_rawdata, diff_file, diff_dumpdir):
* src/create.c (create_archive, restore_parent_fd, dump_file0):
* src/delete.c (delete_archive_members):
* src/exclist.c (cvs_addfn):
* src/extract.c (set_mode, mark_after_links, delay_set_stat)
(repair_delayed_set_stat, make_directories, file_newer_p)
(maybe_recoverable, apply_nonancestor_delayed_set_stat)
(extract_dir, open_output_file, find_delayed_link_source)
(create_placeholder_file, extract_symlink, extract_node)
(extract_fifo, apply_delayed_link):
* src/incremen.c (update_parent_directory, scan_directory)
(read_obstack, read_incr_db_2, write_directory_file)
(try_purge_directory):
* src/map.c (map_read):
* src/misc.c (maybe_backup_file, undo_last_backup, chdir_do)
(tar_savedir):
* src/names.c (handle_file_selection_option, add_file_id)
(handle_option, read_next_name, add_hierarchy_to_namelist)
(collect_and_sort_names):
* src/system.c (run_decompress_program, dec_to_env, time_to_env)
(oct_to_env, str_to_env, chr_to_env, sys_exec_setmtime_script):
* src/tar.c (get_date_or_file, parse_default_options)
(decode_options, main):
* src/unlink.c (flush_deferred_unlinks):
* src/update.c (append_file):
* src/xattrs.c (xattrs__acls_set, xattrs_xattrs_set):
Prefer < 0 when looking at syscalls; prefer != 0 to nothing
when testing an integer in a boolean context.
This is for style, not substance; for example, it’s easier
to read ‘if (wordsplit (...) != WRDSE_OK) ...’ than
‘if (wordsplit (...)) ...’ if you don’t already know that
wordsplit returns an enum rather than bool.
* src/names.c (add_file_id, read_next_name, regex_usage_warning):
* src/transform.c (parse_xform_flags):
Return bool not int, possibly inverting sense so that true means OK.
All callers changed.
* src/tar.c (main): Report errno info if stdopen fails.

17 files changed:
src/buffer.c
src/checkpoint.c
src/compare.c
src/create.c
src/delete.c
src/exclist.c
src/extract.c
src/incremen.c
src/map.c
src/misc.c
src/names.c
src/system.c
src/tar.c
src/transform.c
src/unlink.c
src/update.c
src/xattrs.c

index d3589f17f38dce69b6b60e2ae5ae800c50398109..7b0064455384cb297e98672b29cb9c5a2f9c2366 100644 (file)
@@ -654,7 +654,7 @@ available_space_after (union block *pointer)
 void
 xclose (int fd)
 {
-  if (close (fd) != 0)
+  if (close (fd) < 0)
     close_error (_("(pipe)"));
 }
 
@@ -949,7 +949,7 @@ archive_is_dev (void)
 {
   struct stat st;
 
-  if (fstat (archive, &st))
+  if (fstat (archive, &st) < 0)
     {
       stat_diag (*archive_name_cursor);
       return false;
@@ -1143,7 +1143,7 @@ close_archive (void)
   if (verify_option)
     verify_volume ();
 
-  if (rmtclose (archive) != 0)
+  if (rmtclose (archive) < 0)
     close_error (*archive_name_cursor);
 
   sys_wait_for_child (child_pid, hit_eof);
@@ -1158,7 +1158,7 @@ static void
 write_fatal_details (char const *name, ssize_t status, idx_t size)
 {
   write_error_details (name, status, size);
-  if (rmtclose (archive) != 0)
+  if (rmtclose (archive) < 0)
     close_error (*archive_name_cursor);
   sys_wait_for_child (child_pid, false);
   fatal_exit ();
@@ -1178,7 +1178,7 @@ init_volume_number (void)
                  quotearg_colon (volno_file_option));
       if (ferror (file))
         read_error (volno_file_option);
-      if (fclose (file) != 0)
+      if (fclose (file) < 0)
         close_error (volno_file_option);
     }
   else if (errno != ENOENT)
@@ -1196,7 +1196,7 @@ closeout_volume_number (void)
       fprintf (file, "%jd\n", global_volno);
       if (ferror (file))
         write_error (volno_file_option);
-      if (fclose (file) != 0)
+      if (fclose (file) < 0)
         close_error (volno_file_option);
     }
   else
@@ -1338,7 +1338,7 @@ new_volume (enum access_mode mode)
   continued_file_size = continued_file_offset = 0;
   current_block = record_start;
 
-  if (rmtclose (archive) != 0)
+  if (rmtclose (archive) < 0)
     close_error (*archive_name_cursor);
 
   archive_name_cursor++;
@@ -1358,7 +1358,7 @@ new_volume (enum access_mode mode)
         {
           if (volno_file_option)
             closeout_volume_number ();
-         if (sys_exec_info_script (archive_name_cursor, global_volno + 1))
+         if (sys_exec_info_script (archive_name_cursor, global_volno + 1) != 0)
            paxfatal (0, _("%s command failed"), quote (info_script_option));
         }
       else
@@ -1538,7 +1538,7 @@ try_new_volume (void)
          return false;
        }
 
-      if (strcmp (continued_file_name, bufmap_head->file_name))
+      if (strcmp (continued_file_name, bufmap_head->file_name) != 0)
         {
           if ((archive_format == GNU_FORMAT || archive_format == OLDGNU_FORMAT)
               && strlen (bufmap_head->file_name) >= NAME_FIELD_SIZE
index c0a4ce52a2d3dbbc32fae1095ee35772a4405deb..b6725dfdeaeeb71e4de483cb3da06dd09121639c 100644 (file)
@@ -282,7 +282,8 @@ format_checkpoint_string (FILE *fp, intmax_t len,
                    ws.ws_delim = ",";
                    if (wordsplit (arg, &ws,
                                   (WRDSF_NOVAR | WRDSF_NOCMD
-                                   | WRDSF_QUOTE | WRDSF_DELIM)))
+                                   | WRDSF_QUOTE | WRDSF_DELIM))
+                       != WRDSE_OK)
                      paxerror (0, _("cannot split string '%s': %s"),
                                arg, wordsplit_strerror (&ws));
                    else if (3 < ws.ws_wordc)
index 0a9653a16e2c38435d09d2f3aed1c7a4a69a12c2..ba46a273982b5457aa09c565af67a61fa4aaae4a 100644 (file)
@@ -105,7 +105,7 @@ process_rawdata (idx_t bytes, char *buffer)
       return false;
     }
 
-  if (memcmp (buffer, diff_buffer, bytes))
+  if (memcmp (buffer, diff_buffer, bytes) != 0)
     {
       report_difference (&current_stat_info, _("Contents differ"));
       return false;
@@ -233,7 +233,7 @@ diff_file (void)
                {
                  struct timespec atime = get_stat_atime (&stat_data);
                  if (set_file_atime (diff_handle, chdir_fd, file_name, atime)
-                     != 0)
+                     < 0)
                    utime_error (file_name);
                }
 
@@ -370,7 +370,7 @@ diff_dumpdir (struct tar_stat_info *dir)
       int fd = subfile_open (dir->parent, dir->orig_file_name, open_read_flags);
       if (fd < 0)
        diag = open_diag;
-      else if (fstat (fd, &dir->stat))
+      else if (fstat (fd, &dir->stat) < 0)
         {
          diag = stat_diag;
           close (fd);
@@ -387,7 +387,7 @@ diff_dumpdir (struct tar_stat_info *dir)
 
   if (dumpdir_buffer)
     {
-      if (dumpdir_cmp (dir->dumpdir, dumpdir_buffer))
+      if (dumpdir_cmp (dir->dumpdir, dumpdir_buffer) != 0)
        report_difference (dir, _("Contents differ"));
     }
   else
index 5b7b91ae8eea4ceccc56021cbad16fba563ed33c..edda90b2cf0da1fd2df1a531b2297bf637c2b936 100644 (file)
@@ -1346,7 +1346,7 @@ create_archive (void)
                              break;
                            }
                          st.fd = fd;
-                         if (fstat (fd, &st.stat) != 0)
+                         if (fstat (fd, &st.stat) < 0)
                            {
                              file_removed_diag (p->name, !p->parent,
                                                 stat_diag);
@@ -1555,9 +1555,9 @@ restore_parent_fd (struct tar_stat_info const *st)
 
       if (parentfd < 0)
        parentfd = - errno;
-      else if (! (fstat (parentfd, &parentstat) == 0
-                 && parent->stat.st_ino == parentstat.st_ino
-                 && parent->stat.st_dev == parentstat.st_dev))
+      else if (fstat (parentfd, &parentstat) < 0
+              || parent->stat.st_ino != parentstat.st_ino
+              || parent->stat.st_dev != parentstat.st_dev)
        {
          close (parentfd);
          parentfd = IMPOSTOR_ERRNO;
@@ -1569,12 +1569,12 @@ restore_parent_fd (struct tar_stat_info const *st)
                               open_searchdir_flags);
          if (0 <= origfd)
            {
-             if (fstat (parentfd, &parentstat) == 0
-                 && parent->stat.st_ino == parentstat.st_ino
-                 && parent->stat.st_dev == parentstat.st_dev)
-               parentfd = origfd;
-             else
+             if (fstat (parentfd, &parentstat) < 0
+                 || parent->stat.st_ino != parentstat.st_ino
+                 || parent->stat.st_dev != parentstat.st_dev)
                close (origfd);
+             else
+               parentfd = origfd;
            }
        }
 
@@ -1619,7 +1619,7 @@ dump_file0 (struct tar_stat_info *st, char const *name, char const *p)
       errno = - parentfd;
       diag = open_diag;
     }
-  else if (fstatat (parentfd, name, &st->stat, fstatat_flags) != 0)
+  else if (fstatat (parentfd, name, &st->stat, fstatat_flags) < 0)
     diag = stat_diag;
   else if (file_dumpable_p (&st->stat))
     {
@@ -1629,7 +1629,7 @@ dump_file0 (struct tar_stat_info *st, char const *name, char const *p)
       else
        {
          st->fd = fd;
-         if (fstat (fd, &st->stat) != 0)
+         if (fstat (fd, &st->stat) < 0)
            diag = stat_diag;
        }
     }
@@ -1804,7 +1804,7 @@ dump_file0 (struct tar_stat_info *st, char const *name, char const *p)
            }
          else if (atime_preserve_option == replace_atime_preserve
                   && timespec_cmp (st->atime, get_stat_atime (&st2)) != 0
-                  && set_file_atime (fd, parentfd, name, st->atime) != 0)
+                  && set_file_atime (fd, parentfd, name, st->atime) < 0)
            utime_error (p);
        }
 
index cc3560671db809e88d267126fd005495f5f287e2..31a5e7d8bc5f16d9347297d729561466593b9f59 100644 (file)
@@ -376,7 +376,7 @@ delete_archive_members (void)
 
       if (! acting_as_filter && ! _isrmt (archive))
        {
-         if (sys_truncate (archive))
+         if (sys_truncate (archive) < 0)
            truncate_warn (archive_name_array[0]);
        }
     }
index ac4c2ca2ff31c1ecefe201f9d1b366281052b35a..75e8b38896e588d7ec9c52da9444be934207e764 100644 (file)
@@ -199,7 +199,8 @@ cvs_addfn (struct exclude *ex, char const *pattern, int options,
 
   options |= EXCLUDE_ALLOC;
   if (wordsplit (pattern, &ws,
-                WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_SQUEEZE_DELIMS))
+                WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_SQUEEZE_DELIMS)
+      != WRDSE_OK)
     return;
   for (idx_t i = 0; i < ws.ws_wordc; i++)
     add_exclude (ex, ws.ws_wordv[i], options);
index a64c214cd2a3569f335fa805198e2bd4cae3403a..876d130759e8c986f105c70698e0c68785208392 100644 (file)
@@ -344,7 +344,7 @@ set_mode (char const *file_name,
       if (MODE_ALL & ~ mode_mask & ~ current_mode_mask)
        {
          struct stat st;
-         if (fd_stat (fd, file_name, &st, atflag) != 0)
+         if (fd_stat (fd, file_name, &st, atflag) < 0)
            {
              stat_error (file_name);
              return;
@@ -357,7 +357,7 @@ set_mode (char const *file_name,
 
       if (current_mode != mode)
        {
-         if (fd_chmod (fd, file_name, mode, atflag, typeflag))
+         if (fd_chmod (fd, file_name, mode, atflag, typeflag) < 0)
            chmod_error_details (file_name, mode);
        }
     }
@@ -492,7 +492,7 @@ mark_after_links (struct delayed_set_stat *head)
       struct stat st;
       h->after_links = 1;
 
-      if (deref_stat (h->file_name, &st) != 0)
+      if (deref_stat (h->file_name, &st) < 0)
        stat_error (h->file_name);
       else
        {
@@ -544,7 +544,8 @@ delay_set_stat (char const *file_name, struct tar_stat_info const *st,
        {
          struct stat real_st;
          if (fstatat (chdir_fd, data->file_name,
-                      &real_st, data->atflag) != 0)
+                      &real_st, data->atflag)
+             < 0)
            {
              stat_error (data->file_name);
            }
@@ -627,7 +628,7 @@ repair_delayed_set_stat (char const *dir,
   for (data = delayed_set_stat_head; data; data = data->next)
     {
       struct stat st;
-      if (fstatat (chdir_fd, data->file_name, &st, data->atflag) != 0)
+      if (fstatat (chdir_fd, data->file_name, &st, data->atflag) < 0)
        {
          stat_error (data->file_name);
          return;
@@ -786,9 +787,9 @@ make_directories (char *file_name, bool *interdir_made)
   *parent_end = '\0';
   struct stat st;
   int stat_status = fstatat (chdir_fd, file_name, &st, 0);
-  if (!stat_status && !S_ISDIR (st.st_mode))
+  if (! (stat_status < 0 || S_ISDIR (st.st_mode)))
     stat_status = -1;
-  if (stat_status)
+  if (stat_status < 0)
     {
       errno = parent_errno;
       mkdir_error (file_name);
@@ -812,7 +813,7 @@ file_newer_p (const char *file_name, struct stat const *stp,
 
   if (!stp)
     {
-      if (deref_stat (file_name, &st) != 0)
+      if (deref_stat (file_name, &st) < 0)
        {
          if (errno != ENOENT)
            {
@@ -873,7 +874,7 @@ maybe_recoverable (char *file_name, bool regular, bool *interdir_made)
        break;
       if (strchr (file_name, '/'))
        {
-         if (deref_stat (file_name, &st) != 0)
+         if (deref_stat (file_name, &st) < 0)
            break;
          stp = &st;
        }
@@ -983,7 +984,7 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
 
       if (check_for_renamed_directories)
        {
-         if (fstatat (chdir_fd, data->file_name, &st, data->atflag) != 0)
+         if (fstatat (chdir_fd, data->file_name, &st, data->atflag) < 0)
            {
              stat_error (data->file_name);
              skip_this_one = 1;
@@ -1075,7 +1076,7 @@ extract_dir (char *file_name, int typeflag)
     {
       struct stat st;
 
-      if (fstatat (chdir_fd, ".", &st, 0) != 0)
+      if (fstatat (chdir_fd, ".", &st, 0) < 0)
        stat_diag (".");
       else
        root_device = st.st_dev;
@@ -1248,7 +1249,7 @@ open_output_file (char const *file_name, int typeflag, mode_t mode,
       else
        {
          struct stat st;
-         if (fstat (fd, &st) != 0)
+         if (fstat (fd, &st) < 0)
            {
              int e = errno;
              close (fd);
@@ -1402,7 +1403,7 @@ find_delayed_link_source (char const *name)
   if (!delayed_link_table)
     return false;
 
-  if (fstatat (chdir_fd, name, &st, AT_SYMLINK_NOFOLLOW))
+  if (fstatat (chdir_fd, name, &st, AT_SYMLINK_NOFOLLOW) < 0)
     {
       if (errno != ENOENT)
        stat_error (name);
@@ -1453,12 +1454,12 @@ create_placeholder_file (char *file_name, bool is_symlink, bool *interdir_made)
        }
       }
 
-  if (fstat (fd, &st) != 0)
+  if (fstat (fd, &st) < 0)
     {
       stat_error (file_name);
       close (fd);
     }
-  else if (close (fd) != 0)
+  else if (close (fd) < 0)
     close_error (file_name);
   else
     {
@@ -1590,7 +1591,7 @@ extract_symlink (char *file_name, MAYBE_UNUSED int typeflag)
          || contains_dot_dot (current_stat_info.link_name)))
     return create_placeholder_file (file_name, true, &interdir_made);
 
-  while (symlinkat (current_stat_info.link_name, chdir_fd, file_name) != 0)
+  while (symlinkat (current_stat_info.link_name, chdir_fd, file_name) < 0)
     switch (maybe_recoverable (file_name, false, &interdir_made))
       {
       case RECOVER_OK:
@@ -1630,7 +1631,7 @@ extract_node (char *file_name, int typeflag)
                 & ~ (0 < same_owner_option ? S_IRWXG | S_IRWXO : 0));
 
   while (mknodat (chdir_fd, file_name, mode, current_stat_info.stat.st_rdev)
-        != 0)
+        < 0)
     switch (maybe_recoverable (file_name, false, &interdir_made))
       {
       case RECOVER_OK:
@@ -1659,7 +1660,7 @@ extract_fifo (char *file_name, int typeflag)
   mode_t mode = (current_stat_info.stat.st_mode & MODE_RWX
                 & ~ (0 < same_owner_option ? S_IRWXG | S_IRWXO : 0));
 
-  while (mkfifoat (chdir_fd, file_name, mode) != 0)
+  while (mkfifoat (chdir_fd, file_name, mode) < 0)
     switch (maybe_recoverable (file_name, false, &interdir_made))
       {
       case RECOVER_OK:
@@ -1897,7 +1898,7 @@ apply_delayed_link (struct delayed_link *ds)
        {
          /* Unlink the placeholder, then create a hard link if possible,
             a symbolic link otherwise.  */
-         if (unlinkat (chdir_fd, source, 0) != 0)
+         if (unlinkat (chdir_fd, source, 0) < 0)
            unlink_error (source);
          else if (valid_source
                   && (linkat (chdir_fd, valid_source, chdir_fd, source, 0)
@@ -1905,10 +1906,10 @@ apply_delayed_link (struct delayed_link *ds)
            ;
          else if (!ds->is_symlink)
            {
-             if (linkat (chdir_fd, ds->target, chdir_fd, source, 0) != 0)
+             if (linkat (chdir_fd, ds->target, chdir_fd, source, 0) < 0)
                link_error (ds->target, source);
            }
-         else if (symlinkat (ds->target, chdir_fd, source) != 0)
+         else if (symlinkat (ds->target, chdir_fd, source) < 0)
            symlink_error (ds->target, source);
          else
            {
index 2224f0b1a43bc05b31f5a1f675068f0abd2c67ce..7e81181bd5c41b37a95b65722411146d58d64a2d 100644 (file)
@@ -472,7 +472,7 @@ update_parent_directory (struct tar_stat_info *parent)
   if (directory)
     {
       struct stat st;
-      if (fstat (parent->fd, &st) != 0)
+      if (fstat (parent->fd, &st) < 0)
        stat_diag (directory->name);
       else
        directory->mtime = get_stat_mtime (&st);
@@ -831,7 +831,8 @@ scan_directory (struct tar_stat_info *st)
                      diag = open_diag;
                    }
                  else if (fstatat (fd, entry + 1, &stsub.stat,
-                                   fstatat_flags) != 0)
+                                   fstatat_flags)
+                          < 0)
                    diag = stat_diag;
                  else if (S_ISDIR (stsub.stat.st_mode))
                    {
@@ -842,7 +843,7 @@ scan_directory (struct tar_stat_info *st)
                      else
                        {
                          stsub.fd = subfd;
-                         if (fstat (subfd, &stsub.stat) != 0)
+                         if (fstat (subfd, &stsub.stat) < 0)
                            diag = stat_diag;
                        }
                    }
@@ -1137,7 +1138,7 @@ read_obstack (FILE *fp, struct obstack *stk, idx_t *pcount)
   int c;
   idx_t i;
 
-  for (i = 0, c = getc (fp); c != EOF && c != 0; c = getc (fp), i++)
+  for (i = 0; 0 < (c = getc (fp)); i++)
     obstack_1grow (stk, c);
   obstack_1grow (stk, 0);
 
@@ -1276,7 +1277,7 @@ read_incr_db_2 (void)
        break;
       ino = i;
 
-      if (read_obstack (listed_incremental_stream, &stk, &s))
+      if (read_obstack (listed_incremental_stream, &stk, &s) != 0)
        break;
 
       name = obstack_finish (&stk);
@@ -1478,9 +1479,9 @@ write_directory_file (void)
   if (! fp)
     return;
 
-  if (fseeko (fp, 0, SEEK_SET) != 0)
+  if (fseeko (fp, 0, SEEK_SET) < 0)
     seek_error (listed_incremental_option);
-  if (sys_truncate (fileno (fp)) != 0)
+  if (sys_truncate (fileno (fp)) < 0)
     truncate_error (listed_incremental_option);
 
   int nsec = start_time.tv_nsec;
@@ -1495,7 +1496,7 @@ write_directory_file (void)
 
   if (ferror (fp))
     write_error (listed_incremental_option);
-  if (fclose (fp) != 0)
+  if (fclose (fp) < 0)
     close_error (listed_incremental_option);
 }
 
@@ -1724,7 +1725,7 @@ try_purge_directory (char const *directory_name)
       free (p);
       p = make_file_name (directory_name, cur);
 
-      if (deref_stat (p, &st) != 0)
+      if (deref_stat (p, &st) < 0)
        {
          if (errno != ENOENT) /* FIXME: Maybe keep a list of renamed
                                  dirs and check it here? */
index 1a1d0402dda37b327e9a0a95bac1d179447b6cb9..c03ff61ddc203ceddd4974b1d07c467b225d8bbc 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -97,7 +97,7 @@ map_read (Hash_table **ptab, char const *file,
       char *colon;
 
       ++line;
-      if (wordsplit (buf, &ws, wsopt))
+      if (wordsplit (buf, &ws, wsopt) != WRDSE_OK)
        paxfatal (0, _("%s:%jd: cannot split line: %s"),
                  file, line, wordsplit_strerror (&ws));
       wsopt |= WRDSF_REUSE;
index c6f01f7981cb425a2173aad6c7af494764f3e6a8..2bc3c013b0cde1d51a53b7c5c90f338de70013e7 100644 (file)
@@ -765,7 +765,7 @@ maybe_backup_file (const char *file_name, bool this_is_the_archive)
   if (this_is_the_archive && _remdev (file_name))
     return true;
 
-  if (deref_stat (file_name, &file_stat) != 0)
+  if (deref_stat (file_name, &file_stat) < 0)
     {
       if (errno == ENOENT)
        return true;
@@ -814,7 +814,7 @@ undo_last_backup (void)
   if (after_backup_name)
     {
       if (renameat (chdir_fd, after_backup_name, chdir_fd, before_backup_name)
-         != 0)
+         < 0)
        {
          int e = errno;
          paxerror (e, _("%s: Cannot rename to %s"),
@@ -1023,7 +1023,7 @@ chdir_do (idx_t i)
          else
            {
              struct wd *stale = &wd[wdcache[CHDIR_CACHE_SIZE - 1]];
-             if (close (stale->fd) != 0)
+             if (close (stale->fd) < 0)
                close_diag (stale->name);
              stale->fd = 0;
              wdcache[CHDIR_CACHE_SIZE - 1] = i;
@@ -1315,7 +1315,7 @@ tar_savedir (const char *name, int must_exist)
              && (ret = streamsavedir (dir, savedir_sort_order))))
     savedir_error (name);
 
-  if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
+  if (dir ? closedir (dir) < 0 : 0 <= fd && close (fd) < 0)
     savedir_error (name);
 
   return ret;
index dc25c333970c791090cd1fea98d345d6e696f1d4..d545280f8cf0dd2dc4546990189043b4ceefecf3 100644 (file)
@@ -391,7 +391,7 @@ handle_file_selection_option (int key, const char *arg)
     case 'X':
       if (add_exclude_file (add_exclude, excluded, arg,
                            exclude_options (), '\n')
-         != 0)
+         < 0)
        paxfatal (errno, "%s", quotearg_colon (arg));
       break;
 
@@ -902,14 +902,14 @@ file_list_name (void)
   return _("command line");
 }
 
-static int
+static bool
 add_file_id (const char *filename)
 {
   struct file_id_list *p;
   struct stat st;
   const char *reading_from;
 
-  if (stat (filename, &st))
+  if (stat (filename, &st) < 0)
     stat_fatal (filename);
   reading_from = file_list_name ();
   for (p = file_id_list; p; p = p->next)
@@ -920,7 +920,7 @@ add_file_id (const char *filename)
                  quotearg_n (0, filename),
                  reading_from, p->from_file);
        set_char_quoting (NULL, ':', oldc);
-       return 1;
+       return false;
       }
   p = xmalloc (sizeof *p);
   p->next = file_id_list;
@@ -928,7 +928,7 @@ add_file_id (const char *filename)
   p->dev = st.st_dev;
   p->from_file = reading_from;
   file_id_list = p;
-  return 0;
+  return true;
 }
 
 /* Chop trailing slashes.  */
@@ -994,7 +994,7 @@ handle_option (const char *str, struct name_elt const *ent)
     return 1;
 
   ws.ws_offs = 1;
-  if (wordsplit (str, &ws, WRDSF_DEFFLAGS|WRDSF_DOOFFS))
+  if (wordsplit (str, &ws, WRDSF_DEFFLAGS | WRDSF_DOOFFS) != WRDSE_OK)
     paxfatal (0, _("cannot split string '%s': %s"),
              str, wordsplit_strerror (&ws));
   int argc;
@@ -1010,22 +1010,22 @@ handle_option (const char *str, struct name_elt const *ent)
   return 0;
 }
 
-static int
+static bool
 read_next_name (struct name_elt *ent, struct name_elt *ret)
 {
   if (!ent->v.file.fp)
     {
-      if (!strcmp (ent->v.file.name, "-"))
+      if (strcmp (ent->v.file.name, "-") == 0)
        {
          request_stdin ("-T");
          ent->v.file.fp = stdin;
        }
       else
        {
-         if (add_file_id (ent->v.file.name))
+         if (!add_file_id (ent->v.file.name))
            {
              name_list_advance ();
-             return 1;
+             return false;
            }
          FILE *fp = fopen (ent->v.file.name, "r");
          if (!fp)
@@ -1057,20 +1057,20 @@ read_next_name (struct name_elt *ent, struct name_elt *ret)
              if (handle_option (name_buffer, ent) == 0)
                {
                  name_list_adjust ();
-                 return 1;
+                 return false;
                }
            }
          chopslash (name_buffer);
          ret->type = NELT_NAME;
          ret->v.name = name_buffer;
-         return 0;
+         return true;
 
        case file_list_end:
          if (strcmp (ent->v.file.name, "-"))
            fclose (ent->v.file.fp);
          ent->v.file.fp = NULL;
          name_list_advance ();
-         return 1;
+         return false;
        }
     }
 }
@@ -1110,7 +1110,7 @@ name_next_elt (bool change_dirs)
          break;
 
        case NELT_FILE:
-         if (read_next_name (ep, &entry) == 0)
+         if (read_next_name (ep, &entry))
            return &entry;
          continue;
 
@@ -1392,20 +1392,20 @@ all_names_found (struct tar_stat_info *p)
   return true;
 }
 
-static int
+static bool
 regex_usage_warning (const char *name)
 {
-  static int warned_once = 0;
+  static bool warned_once;
 
   /* Warn about implicit use of the wildcards in command line arguments.
      (Default for tar prior to 1.15.91, but changed afterwards) */
   if (wildcards == default_wildcards
       && fnmatch_pattern_has_wildcards (name, 0))
     {
-      warned_once = 1;
       paxwarn (0, _("Pattern matching characters used in file names"));
       paxwarn (0, _("Use --wildcards to enable pattern matching,"
                    " or --no-wildcards to suppress this warning"));
+      warned_once = true;
     }
   return warned_once;
 }
@@ -1470,13 +1470,9 @@ label_notfound (void)
   nametail = NULL;
 
   if (same_order_option)
-    {
-      const char *name;
-
-      while ((name = name_next (true))
-            && regex_usage_warning (name) == 0)
-       ;
-    }
+    for (char const *name;
+        (name = name_next (true)) && !regex_usage_warning (name); )
+      continue;
 }
 \f
 /* Sorting name lists.  */
@@ -1651,7 +1647,7 @@ add_hierarchy_to_namelist (struct tar_stat_info *st, struct name *name)
              else
                {
                  subdir.fd = subfd;
-                 if (fstat (subfd, &subdir.stat) != 0)
+                 if (fstat (subfd, &subdir.stat) < 0)
                    stat_diag (namebuf);
                  else if (! (O_DIRECTORY || S_ISDIR (subdir.stat.st_mode)))
                    {
@@ -1775,7 +1771,7 @@ collect_and_sort_names (void)
 
       tar_stat_init (&st);
 
-      if (deref_stat (name->name, &st.stat) != 0)
+      if (deref_stat (name->name, &st.stat) < 0)
        {
          stat_diag (name->name);
          continue;
@@ -1789,7 +1785,7 @@ collect_and_sort_names (void)
          else
            {
              st.fd = dir_fd;
-             if (fstat (dir_fd, &st.stat) != 0)
+             if (fstat (dir_fd, &st.stat) < 0)
                stat_diag (name->name);
              else if (O_DIRECTORY || S_ISDIR (st.stat.st_mode))
                {
index eaca1824f32af3003782f2f286702d0ce72f9008..fd2a290e8be3a58c5174502867253bf9ff230f3e 100644 (file)
@@ -517,7 +517,7 @@ run_decompress_program (void)
          warnopt (WARN_DECOMPRESS_PROGRAM, errno, _("cannot run %s"), prog);
          warnopt (WARN_DECOMPRESS_PROGRAM, 0, _("trying %s"), p);
        }
-      if (wordsplit (p, &ws, wsflags))
+      if (wordsplit (p, &ws, wsflags) != WRDSE_OK)
        paxfatal (0, _("cannot split string '%s': %s"),
                  p, wordsplit_strerror (&ws));
       wsflags |= WRDSF_REUSE;
@@ -650,7 +650,7 @@ static void
 dec_to_env (char const *envar, uintmax_t num)
 {
   char numstr[UINTMAX_STRSIZE_BOUND];
-  if (setenv (envar, umaxtostr (num, numstr), 1) != 0)
+  if (setenv (envar, umaxtostr (num, numstr), 1) < 0)
     xalloc_die ();
 }
 
@@ -658,7 +658,7 @@ static void
 time_to_env (char const *envar, struct timespec t)
 {
   char buf[TIMESPEC_STRSIZE_BOUND];
-  if (setenv (envar, code_timespec (t, buf), 1) != 0)
+  if (setenv (envar, code_timespec (t, buf), 1) < 0)
     xalloc_die ();
 }
 
@@ -670,7 +670,7 @@ oct_to_env (char const *envar, mode_t m)
   if (EXPR_SIGNED (m) && sizeof m < sizeof um)
     um &= ~ (UINTMAX_MAX << TYPE_WIDTH (m));
   sprintf (buf, "%#"PRIoMAX, um);
-  if (setenv (envar, buf, 1) != 0)
+  if (setenv (envar, buf, 1) < 0)
     xalloc_die ();
 }
 
@@ -679,7 +679,7 @@ str_to_env (char const *envar, char const *str)
 {
   if (str)
     {
-      if (setenv (envar, str, 1) != 0)
+      if (setenv (envar, str, 1) < 0)
        xalloc_die ();
     }
   else
@@ -692,7 +692,7 @@ chr_to_env (char const *envar, char c)
   char buf[2];
   buf[0] = c;
   buf[1] = 0;
-  if (setenv (envar, buf, 1) != 0)
+  if (setenv (envar, buf, 1) < 0)
     xalloc_die ();
 }
 
@@ -932,7 +932,7 @@ sys_exec_setmtime_script (const char *script_name,
   char *cp;
   int rc = 0;
 
-  if (pipe (p))
+  if (pipe (p) < 0)
     paxfatal (errno, _("pipe failed"));
 
   if ((pid = xfork ()) == 0)
@@ -943,11 +943,8 @@ sys_exec_setmtime_script (const char *script_name,
       strcat (command, " ");
       strcat (command, file_name);
 
-      if (dirfd != AT_FDCWD)
-       {
-         if (fchdir (dirfd))
-           paxfatal (errno, _("chdir failed"));
-       }
+      if (dirfd != AT_FDCWD && fchdir (dirfd) < 0)
+       paxfatal (errno, _("chdir failed"));
 
       close (p[0]);
       if (dup2 (p[1], STDOUT_FILENO) < 0)
index ea2b2f3b9218de89e397e188c91fe7236f167609..3a4421e9389fb0ed4311ccb1e8bcc4cfc6f5003b 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -1141,7 +1141,7 @@ get_date_or_file (struct tar_args *args, const char *option,
       || *str == '.')
     {
       struct stat st;
-      if (stat (str, &st) != 0)
+      if (stat (str, &st) < 0)
        {
          stat_error (str);
          paxusage (_("Date sample file not found"));
@@ -2331,7 +2331,7 @@ parse_default_options (struct tar_args *args)
     return;
 
   ws.ws_offs = 1;
-  if (wordsplit (opts, &ws, WRDSF_DEFFLAGS|WRDSF_DOOFFS))
+  if (wordsplit (opts, &ws, WRDSF_DEFFLAGS | WRDSF_DOOFFS) != WRDSE_OK)
     paxfatal (0, _("cannot split TAR_OPTIONS: %s"), wordsplit_strerror (&ws));
   if (ws.ws_wordc)
     {
@@ -2754,7 +2754,7 @@ decode_options (int argc, char **argv)
       for (archive_name_cursor = archive_name_array;
           archive_name_cursor < archive_name_array + archive_names;
           archive_name_cursor++)
-       if (!strcmp (*archive_name_cursor, "-"))
+       if (strcmp (*archive_name_cursor, "-") == 0)
          request_stdin ("-f");
       break;
 
@@ -2764,7 +2764,7 @@ decode_options (int argc, char **argv)
       for (archive_name_cursor = archive_name_array;
           archive_name_cursor < archive_name_array + archive_names;
           archive_name_cursor++)
-       if (!strcmp (*archive_name_cursor, "-"))
+       if (strcmp (*archive_name_cursor, "-") == 0)
          paxusage (_("Options '-Aru' are incompatible with '-f -'"));
 
     default:
@@ -2846,10 +2846,11 @@ main (int argc, char **argv)
   set_quoting_style (0, DEFAULT_QUOTING_STYLE);
 
   close_stdout_set_file_name (_("stdout"));
-  /* Make sure we have first three descriptors available */
-  if (stdopen ())
-    paxfatal (0, _("failed to assert availability"
-                  " of the standard file descriptors"));
+
+  int err = stdopen ();
+  if (err != 0)
+    paxfatal (err, _("failed to assert availability"
+                    " of the standard file descriptors"));
 
   /* System V fork+wait does not work if SIGCHLD is ignored.  */
   signal (SIGCHLD, SIG_DFL);
@@ -2927,7 +2928,7 @@ main (int argc, char **argv)
 
   if (stdlis == stdout)
     close_stdout ();
-  else if (ferror (stderr) || fclose (stderr) != 0)
+  else if (ferror (stderr) || fclose (stderr) < 0)
     set_exit_status (TAREXIT_FAILURE);
 
   return exit_status;
index aa7c06093a9f13b195c77069195677da946f2dbe..fa436817a0536f9354f9954ba8d487db03fb12fe 100644 (file)
@@ -134,7 +134,7 @@ add_backref_segment (struct transform *tf, idx_t ref)
   segm->v.ref = ref;
 }
 
-static int
+static bool
 parse_xform_flags (int *pflags, int c)
 {
   switch (c)
@@ -164,9 +164,9 @@ parse_xform_flags (int *pflags, int c)
       break;
 
     default:
-      return 1;
+      return false;
     }
-  return 0;
+  return true;
 }
 
 static void
@@ -199,7 +199,7 @@ parse_transform_expr (const char *expr)
                  expr++;
                  break;
                }
-             if (parse_xform_flags (&transform_flags, *expr))
+             if (!parse_xform_flags (&transform_flags, *expr))
                paxusage (_("Unknown transform flag: %c"), *expr);
            }
          return expr;
@@ -255,7 +255,7 @@ parse_transform_expr (const char *expr)
        break;
 
       default:
-       if (parse_xform_flags (&tf->flags, *p))
+       if (!parse_xform_flags (&tf->flags, *p))
          paxusage (_("Unknown flag in transform expression: %c"), *p);
       }
 
index 59a72d7b8d2897cb970fb1a9c3805c36b8785e53..936c23142fb7b291a0f326c4c1570b2812b8259e 100644 (file)
@@ -106,7 +106,7 @@ flush_deferred_unlinks (bool force)
              else
                fname = p->file_name;
 
-             if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) != 0)
+             if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) < 0)
                {
                  switch (errno)
                    {
@@ -132,7 +132,7 @@ flush_deferred_unlinks (bool force)
            }
          else
            {
-             if (unlinkat (chdir_fd, p->file_name, 0) != 0 && errno != ENOENT)
+             if (unlinkat (chdir_fd, p->file_name, 0) < 0 && errno != ENOENT)
                unlink_error (p->file_name);
            }
          dunlink_reclaim (p);
@@ -166,7 +166,7 @@ flush_deferred_unlinks (bool force)
          else
            fname = p->file_name;
 
-         if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) != 0)
+         if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) < 0)
            {
              if (errno != ENOENT)
                rmdir_error (fname);
index 0f602efeb82ac16afdc791cc6b7c623ef86b75cc..8dccf545e3d8627e4359016234c3a791f0ecaa49 100644 (file)
@@ -68,7 +68,7 @@ append_file (char *file_name)
       set_next_block_after (start + (status - 1) / BLOCKSIZE);
     }
 
-  if (close (handle) != 0)
+  if (close (handle) < 0)
     close_error (file_name);
 }
 
index fa95ef34e371f3a7d7390c4c0477c83259d6513c..1cee78de501a70d12bce60e559140219fc8c6cec 100644 (file)
@@ -293,7 +293,7 @@ xattrs__acls_set (struct tar_stat_info const *st,
       /* No "default" IEEE 1003.1e ACL set for directory.  At this moment,
          FILE_NAME may already have inherited default acls from parent
          directory;  clean them up. */
-      if (acl_delete_def_file_at (chdir_fd, file_name))
+      if (acl_delete_def_file_at (chdir_fd, file_name) < 0)
        warnopt (WARN_XATTR_WRITE, errno,
                  _("acl_delete_def_file_at: Cannot drop default POSIX ACLs "
                    "for file '%s'"),
@@ -737,7 +737,7 @@ xattrs_xattrs_set (struct tar_stat_info const *st,
              the first run except 'security.capability' which is restored in
              'later_run == 1'.  */
           if (typeflag == REGTYPE
-              && later_run == !!strcmp (keyword, "security.capability"))
+              && later_run == (strcmp (keyword, "security.capability") != 0))
             continue;
 
           if (xattrs_masked_out (keyword, false /* extracting */ ))