]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Prefer other types to int in map.c
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 01:51:05 +0000 (18:51 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
* src/map.c (map_read): Prefer bool for booleans.
(owner_map_translate, group_map_translate):
Return void, not int, as nobody uses the return value.

src/common.h
src/map.c

index 5a5bc61895bbf91fae7cd0b469363a7a2aa2fa5e..14f7ff98572d94a80f77c0b8e1f82cc46947d9f1 100644 (file)
@@ -1060,9 +1060,9 @@ void exclude_vcs_ignores (void);
 
 /* Module map.c */
 void owner_map_read (char const *name);
-int owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name);
+void owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name);
 void group_map_read (char const *file);
-int group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name);
+void group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name);
 
 
 _GL_INLINE_HEADER_END
index c03ff61ddc203ceddd4974b1d07c467b225d8bbc..fcd75f42235b9df60abc0d5e4c88b06150dfc79d 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -79,7 +79,7 @@ map_read (Hash_table **ptab, char const *file,
   struct wordsplit ws;
   int wsopt;
   intmax_t line;
-  int err = 0;
+  bool err = false;
 
   fp = fopen (file, "r");
   if (!fp)
@@ -106,7 +106,7 @@ map_read (Hash_table **ptab, char const *file,
       if (ws.ws_wordc != 2)
        {
          error (0, 0, _("%s:%jd: malformed line"), file, line);
-         err = 1;
+         err = true;
          continue;
        }
 
@@ -114,7 +114,7 @@ map_read (Hash_table **ptab, char const *file,
        {
          if (!parse_id (&orig_id, ws.ws_wordv[0]+1, what, maxval, file, line))
            {
-             err = 1;
+             err = true;
              continue;
            }
        }
@@ -125,7 +125,7 @@ map_read (Hash_table **ptab, char const *file,
            {
              error (0, 0, _("%s:%jd: can't obtain %s of %s"),
                     file, line, what, ws.ws_wordv[0]);
-             err = 1;
+             err = true;
              continue;
            }
        }
@@ -138,7 +138,7 @@ map_read (Hash_table **ptab, char const *file,
          *colon++ = 0;
          if (!parse_id (&new_id, colon, what, maxval, file, line))
            {
-             err = 1;
+             err = true;
              continue;
            }
        }
@@ -146,7 +146,7 @@ map_read (Hash_table **ptab, char const *file,
        {
          if (!parse_id (&new_id, ws.ws_wordv[1], what, maxval, file, line))
            {
-             err = 1;
+             err = true;
              continue;
            }
        }
@@ -158,7 +158,7 @@ map_read (Hash_table **ptab, char const *file,
            {
              error (0, 0, _("%s:%jd: can't obtain %s of %s"),
                     file, line, what, ws.ws_wordv[1]);
-             err = 1;
+             err = true;
              continue;
            }
        }
@@ -197,11 +197,9 @@ owner_map_read (char const *file)
   map_read (&owner_map, file, name_to_uid, "UID", TYPE_MAXIMUM (uid_t));
 }
 
-int
+void
 owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name)
 {
-  int rc = 1;
-
   if (owner_map)
     {
       struct mapentry ent, *res;
@@ -212,23 +210,15 @@ owner_map_translate (uid_t uid, uid_t *new_uid, char const **new_name)
        {
          *new_uid = res->new_id;
          *new_name = res->new_name;
-         return 0;
+         return;
        }
     }
 
   uid_t minus_1 = -1;
   if (owner_option != minus_1)
-    {
-      *new_uid = owner_option;
-      rc = 0;
-    }
+    *new_uid = owner_option;
   if (owner_name_option)
-    {
-      *new_name = owner_name_option;
-      rc = 0;
-    }
-
-  return rc;
+    *new_name = owner_name_option;
 }
 \f
 /* GID translation */
@@ -248,11 +238,9 @@ group_map_read (char const *file)
   map_read (&group_map, file, name_to_gid, "GID", TYPE_MAXIMUM (gid_t));
 }
 
-int
+void
 group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name)
 {
-  int rc = 1;
-
   if (group_map)
     {
       struct mapentry ent, *res;
@@ -263,21 +251,13 @@ group_map_translate (gid_t gid, gid_t *new_gid, char const **new_name)
        {
          *new_gid = res->new_id;
          *new_name = res->new_name;
-         return 0;
+         return;
        }
     }
 
   gid_t minus_1 = -1;
   if (group_option != minus_1)
-    {
-      *new_gid = group_option;
-      rc = 0;
-    }
+    *new_gid = group_option;
   if (group_name_option)
-    {
-      *new_name = group_name_option;
-      rc = 0;
-    }
-
-  return rc;
+    *new_name = group_name_option;
 }