From: Ulf Hermann <ulf.hermann@qt.io>
To: <elfutils-devel@sourceware.org>
Subject: [PATCH] Use octal numbers rather than permission macros
Date: Thu, 04 May 2017 16:05:00 -0000 [thread overview]
Message-ID: <35b0c41e-42f2-e998-1725-16d7a085312a@qt.io> (raw)
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
reply other threads:[~2017-05-04 15:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=35b0c41e-42f2-e998-1725-16d7a085312a@qt.io \
--to=ulf.hermann@qt.io \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).