[PATCH] Use octal numbers rather than permission macros

Ulf Hermann ulf.hermann@qt.io
Thu May 4 16:05:00 GMT 2017


The permission macros are not guaranteed to be defined and the octal
numbers are rather well known.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 src/ChangeLog       | 7 +++++++
 src/ar.c            | 8 ++++----
 src/elfcompress.c   | 4 ++--
 src/ranlib.c        | 2 +-
 src/strip.c         | 2 +-
 tests/ChangeLog     | 4 ++++
 tests/elfstrmerge.c | 4 ++--
 7 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 44b4395..15cd55f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
 2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
 
+	* ar.c: Use octal numbers instead of permission macros.
+	* elfcompress.c: Likewise.
+	* ranlib.c: Likewise.
+	* strip.c: Likewise.
+
+2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
+
 	* unstrip.c: Use strndup and free instead of strndupa.
 
 2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
diff --git a/src/ar.c b/src/ar.c
index 91391b1..cc47f10 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -799,7 +799,7 @@ cannot rename temporary file to %.*s"),
 #if HAVE_DECL_FCHMOD
 		  /* Set the mode of the new file to the same values the
 		     original file has.  */
-		  fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+		  fchmod (newfd, st.st_mode & 07777) != 0 ||
 #endif
 		  (
 #if HAVE_DECL_FCHOWN
@@ -1057,7 +1057,7 @@ do_oper_delete (const char *arfname, char **argv, int argc,
 #if HAVE_DECL_FCHMOD
       /* Set the mode of the new file to the same values the original file
          has.  */
-      fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+      fchmod (newfd, st.st_mode & 07777) != 0 ||
 #endif
       (
 #if HAVE_DECL_FCHOWN
@@ -1399,7 +1399,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
     newfd = mkstemp (tmpfname);
   else
     {
-      newfd = open (arfname, O_RDWR | O_BINARY | O_CREAT | O_EXCL, DEFFILEMODE);
+      newfd = open (arfname, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0666);
       if (newfd == -1 && errno == EEXIST)
 	/* Bah, first the file did not exist, now it does.  Restart.  */
 	return do_oper_insert (oper, arfname, argv, argc, member);
@@ -1521,7 +1521,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
 #if HAVE_DECL_FCHMOD
           /* Set the mode of the new file to the same values the original file
              has.  */
-          fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+          fchmod (newfd, st.st_mode & 07777) != 0 ||
 #endif
 	  (
 #if HAVE_DECL_FCHOWN
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 5dbeb57..6080db7 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -542,7 +542,7 @@ process_file (const char *fname)
   else
     {
       fnew = xstrdup (foutput);
-      fdnew = open (fnew, O_WRONLY | O_BINARY | O_CREAT, st.st_mode & ALLPERMS);
+      fdnew = open (fnew, O_WRONLY | O_BINARY | O_CREAT, st.st_mode & 07777);
     }
 
   if (fdnew < 0)
@@ -1237,7 +1237,7 @@ process_file (const char *fname)
 
 #if HAVE_DECL_FCHMOD
   /* Try to match mode and owner.group of the original file.  */
-  if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0)
+  if (fchmod (fdnew, st.st_mode & 07777) != 0)
     if (verbose >= 0)
       error (0, errno, "Couldn't fchmod %s", fnew);
 #endif
diff --git a/src/ranlib.c b/src/ranlib.c
index 41057de..22aac28 100644
--- a/src/ranlib.c
+++ b/src/ranlib.c
@@ -261,7 +261,7 @@ handle_file (const char *fname)
 #if HAVE_DECL_FCHMOD
 	      /* Set the mode of the new file to the same values the
 		 original file has.  */
-	      fchmod (newfd, st.st_mode & ALLPERMS) != 0 ||
+	      fchmod (newfd, st.st_mode & 07777) != 0 ||
 #endif
 	      (
 #if HAVE_DECL_FCHOWN
diff --git a/src/strip.c b/src/strip.c
index 60f6700..14d2249 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -347,7 +347,7 @@ process_file (const char *fname)
   switch (elf_kind (elf))
     {
     case ELF_K_ELF:
-      result = handle_elf (fd, elf, NULL, fname, st.st_mode & ACCESSPERMS,
+      result = handle_elf (fd, elf, NULL, fname, st.st_mode & 0777,
 			   preserve_dates ? tv : NULL);
       break;
 
diff --git a/tests/ChangeLog b/tests/ChangeLog
index fef6f55..9c04404 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,9 @@
 2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
 
+	* elfstrmerge.c: Use 07777 instead of ALLPERMS.
+
+2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
+
 	* elfshphehdr.c: For writing, use /dev/null rather than /dev/zero.
 
 2017-05-04  Ulf Hermann  <ulf.hermann@qt.io>
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index ff15f57..5405ed8 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -367,7 +367,7 @@ main (int argc, char **argv)
   else
     {
       fnew = argv[2];
-      fdnew = open (fnew, O_WRONLY | O_CREAT | O_BINARY, st.st_mode & ALLPERMS);
+      fdnew = open (fnew, O_WRONLY | O_CREAT | O_BINARY, st.st_mode & 07777);
     }
 
   if (fdnew < 0)
@@ -652,7 +652,7 @@ main (int argc, char **argv)
 
 #if HAVE_DECL_FCHMOD
   /* Try to match mode and owner.group of the original file.  */
-  if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0)
+  if (fchmod (fdnew, st.st_mode & 07777) != 0)
     error (0, errno, "Couldn't fchmod %s", fnew);
 #endif
 #if HAVE_DECL_FCHOWN
-- 
2.1.4



More information about the Elfutils-devel mailing list