This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] GNU/kFreeBSD: statfs with f_namemax


Hi,

The attached patch was written by
Aurelien Jarno <aurel32@debian.org> to make it work on
GNU/kFreeBSD.  statfs doesn't have a f_namelen member
but does have a f_namemax member.


Kurt

diff --git a/configure.ac b/configure.ac
index f5a3c52..219ba2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -209,6 +209,9 @@ zip_LIBS="$LIBS"
 LIBS="$save_LIBS"
 AC_SUBST([zip_LIBS])
 
+AC_CHECK_MEMBERS([struct statfs.f_namemax],,,[#include <sys/statfs.h>])
+AC_CHECK_MEMBERS([struct statfs.f_namelen],,,[#include <sys/statfs.h>])
+
 dnl The directories with content.
 
 dnl Documentation.
diff --git a/src/ar.c b/src/ar.c
index 2d11b1e..dbfe7c8 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -52,6 +52,13 @@
 
 #include "arlib.h"
 
+#if HAVE_STRUCT_STATFS_F_NAMEMAX
+# define F_NAMELEN(S) ((S).f_namemax)
+#elif HAVE_STRUCT_STATFS_F_NAMELEN
+# define F_NAMELEN(S) ((S).f_namelen)
+#endif
+
+
 
 /* Name and version of program.  */
 static void print_version (FILE *stream, struct argp_state *state);
@@ -460,7 +467,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
   memset (found, '\0', sizeof (found));
 
   struct statfs f;
-  f.f_namelen = 0;
+  F_NAMELEN(f) = 0;
 
   off_t index_off = -1;
   size_t index_size = 0;
@@ -612,14 +619,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))
+			  && (F_NAMELEN(f) != 0 || statfs (".", &f) == 0))
 			{
 			  /* Try to truncate the name.  First find out by how
 			     much.  */
-			  printlen = f.f_namelen;
-			  char truncfname[f.f_namelen + 1];
+			  printlen = F_NAMELEN(f);
+			  char truncfname[F_NAMELEN(f) + 1];
 			  *((char *) mempcpy (truncfname, arhdr->ar_name,
-					      f.f_namelen)) = '\0';
+					      F_NAMELEN(f))) = '\0';
 
 			  xfd = open (truncfname, flags, 0600);
 			}
@@ -702,14 +709,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))
+			  && (F_NAMELEN(f) != 0 || statfs (".", &f) == 0))
 			{
 			  /* Try to truncate the name.  First find out by how
 			     much.  */
-			  printlen = f.f_namelen;
-			  char truncfname[f.f_namelen + 1];
+			  printlen = F_NAMELEN(f);
+			  char truncfname[F_NAMELEN(f) + 1];
 			  *((char *) mempcpy (truncfname, arhdr->ar_name,
-					      f.f_namelen)) = '\0';
+					      F_NAMELEN(f))) = '\0';
 
 			  if (dont_replace_existing)
 			    {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]