]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use pathconf instead of statfs.
authorRoland McGrath <roland@redhat.com>
Fri, 14 Aug 2009 20:10:09 +0000 (13:10 -0700)
committerRoland McGrath <roland@redhat.com>
Fri, 14 Aug 2009 20:10:09 +0000 (13:10 -0700)
src/ChangeLog
src/ar.c

index 19e034ae1989059368b4bea248bd97a04b668ba4..c0ea003b6865504d9017c45e183cb6baed77343f 100644 (file)
@@ -1,3 +1,7 @@
+2009-08-14  Roland McGrath  <roland@redhat.com>
+
+       * ar.c (do_oper_extract): Use pathconf instead of statfs.
+
 2009-08-01  Ulrich Drepper  <drepper@redhat.com>
 
        * debugpred.h: Add two most const.
index 2d11b1ef890d6bdce7a87cc1341468a8a6db8ed1..9be0649ff1f82a8d60c09c676e3b194d13effdd4 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -45,7 +45,6 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/mman.h>
-#include <sys/statfs.h>
 #include <sys/time.h>
 
 #include <system.h>
@@ -459,8 +458,21 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
   bool found[argc];
   memset (found, '\0', sizeof (found));
 
-  struct statfs f;
-  f.f_namelen = 0;
+  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;
@@ -611,15 +623,14 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
                    {
                      int printlen = INT_MAX;
 
-                     if (errno == ENAMETOOLONG && allow_truncate_fname
-                         && (f.f_namelen != 0 || statfs (".", &f) == 0))
+                     if (should_truncate_fname ())
                        {
                          /* Try to truncate the name.  First find out by how
                             much.  */
-                         printlen = f.f_namelen;
-                         char truncfname[f.f_namelen + 1];
+                         printlen = name_max;
+                         char truncfname[name_max + 1];
                          *((char *) mempcpy (truncfname, arhdr->ar_name,
-                                             f.f_namelen)) = '\0';
+                                             name_max)) = '\0';
 
                          xfd = open (truncfname, flags, 0600);
                        }
@@ -701,15 +712,14 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
                    {
                      int printlen = INT_MAX;
 
-                     if (errno == ENAMETOOLONG && allow_truncate_fname
-                         && (f.f_namelen != 0 || statfs (".", &f) == 0))
+                     if (should_truncate_fname ())
                        {
                          /* Try to truncate the name.  First find out by how
                             much.  */
-                         printlen = f.f_namelen;
-                         char truncfname[f.f_namelen + 1];
+                         printlen = name_max;
+                         char truncfname[name_max + 1];
                          *((char *) mempcpy (truncfname, arhdr->ar_name,
-                                             f.f_namelen)) = '\0';
+                                             name_max)) = '\0';
 
                          if (dont_replace_existing)
                            {