]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
ar: Pull should_truncate_fname() into file scope
authorTimm Bäder <tbaeder@redhat.com>
Wed, 3 Feb 2021 14:44:46 +0000 (15:44 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 5 Feb 2021 17:46:07 +0000 (18:46 +0100)
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
src/ChangeLog
src/ar.c

index 9e30df31c20026d5ae9056d2cb7adef05a81bcc4..e65620fdaf4f8715e1bea60c569fa33da6605393 100644 (file)
@@ -1,3 +1,10 @@
+2021-02-03 Timm Bäder <tbaeder@redhat.com>
+
+       * ar.c (do_oper_extract): Extract should_truncate_fname function
+       to...
+       (should_truncate_fname): ...here. New file scope function taking
+       size_t pointer to be read and/or set.
+
 2021-02-02 Timm Bäder <tbaeder@redhat.com>
 
        * readelf.c (print_debug_line_section): Remove unnecessary
index 2a17d0d3c1365480c6a7e1c680f6cb7069876a99..66b2c4fdc4125c016e17d5e812786650bbceaa6b 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -436,6 +436,21 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n)
   return write_retry (newfd, rawfile + off, n) != (ssize_t) n;
 }
 
+static inline bool
+should_truncate_fname (size_t *name_max)
+{
+  if (errno == ENAMETOOLONG && allow_truncate_fname)
+    {
+      if (*name_max == 0)
+       {
+         long int len = pathconf (".", _PC_NAME_MAX);
+         if (len > 0)
+           *name_max = len;
+       }
+      return *name_max != 0;
+    }
+  return false;
+}
 
 static int
 do_oper_extract (int oper, const char *arfname, char **argv, int argc,
@@ -445,21 +460,6 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
   memset (found, '\0', sizeof (found));
 
   size_t name_max = 0;
-  inline bool should_truncate_fname (void)
-  {
-    if (errno == ENAMETOOLONG && allow_truncate_fname)
-      {
-       if (name_max == 0)
-         {
-           long int len = pathconf (".", _PC_NAME_MAX);
-           if (len > 0)
-             name_max = len;
-         }
-       return name_max != 0;
-      }
-    return false;
-  }
-
   off_t index_off = -1;
   size_t index_size = 0;
   off_t cur_off = SARMAG;
@@ -615,7 +615,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
                    {
                      int printlen = INT_MAX;
 
-                     if (should_truncate_fname ())
+                     if (should_truncate_fname (&name_max))
                        {
                          /* Try to truncate the name.  First find out by how
                             much.  */
@@ -704,7 +704,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
                    {
                      int printlen = INT_MAX;
 
-                     if (should_truncate_fname ())
+                     if (should_truncate_fname (&name_max))
                        {
                          /* Try to truncate the name.  First find out by how
                             much.  */