public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: [PATCH 3/6] Fall back on utimes if futimes is not available
Date: Mon, 04 May 2015 02:25:41 +0300	[thread overview]
Message-ID: <1430695544-7336-4-git-send-email-jcmvbkbc@gmail.com> (raw)
In-Reply-To: 1430695544-7336-1-git-send-email-jcmvbkbc@gmail.com

[-- Attachment #1: Type: text/plain, Size: 3235 bytes --]

From: "Anthony G. Basile" <blueness@gentoo.org>

We check if futimes is provided, and if it is not, we fall back
on utimes which is POSIX.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
[Max: move futimes/utimes in strip.c into 'if (tvp != NULL)' blocks.]
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 ChangeLog     |  4 ++++
 configure.ac  |  3 +++
 src/ChangeLog |  6 ++++++
 src/ar.c      |  8 +++++++-
 src/strip.c   | 18 ++++++++++++++++--
 5 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d3e46fc..89045ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2015-05-04  Anthony G. Basile  <blueness@gentoo.org>
 
+	* configure.ac (futimes): Check if function exists.
+
+2015-05-04  Anthony G. Basile  <blueness@gentoo.org>
+
 	* configure.ac (argp_LDADD): Check if libc has argp and set
 	argp_LDADD accordingly.
 
diff --git a/configure.ac b/configure.ac
index 68b7f5b..35dfa08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,9 @@ else
 fi
 AC_SUBST([argp_LDADD])
 
+dnl Check for futimes
+AC_CHECK_FUNC([futimes])
+
 dnl The directories with content.
 
 dnl Documentation.
diff --git a/src/ChangeLog b/src/ChangeLog
index 957eeb3..2ee0d1d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-04  Anthony G. Basile  <blueness@gentoo.org>
+
+	* ar.c (do_oper_extract): Use futimes or utimes depending on
+	HAVE_FUTIMES.
+	* strip.c (handle_elf, handle_ar): Likewise.
+
 2015-05-04  Max Filippov  <jcmvbkbc@gmail.com>
 
 	* addr2line.c (main): Drop mtrace() call and #include <mcheck.h>.
diff --git a/src/ar.c b/src/ar.c
index caed7f3..6882ced 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -685,7 +685,13 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
 		  tv[1].tv_sec = arhdr->ar_date;
 		  tv[1].tv_usec = 0;
 
-		  if (unlikely (futimes (xfd, tv) != 0))
+		  int success;
+#ifdef HAVE_FUTIMES
+		  success = futimes (xfd, tv);
+#else
+		  success = utimes (arhdr->ar_name, tv);
+#endif
+		  if (unlikely (success != 0))
 		    {
 		      error (0, errno,
 			     gettext ("cannot change modification time of %s"),
diff --git a/src/strip.c b/src/strip.c
index e81001e..07b7dc5 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -2087,7 +2087,14 @@ while computing checksum for debug information"));
   /* If requested, preserve the timestamp.  */
   if (tvp != NULL)
     {
-      if (futimes (fd, tvp) != 0)
+      int success;
+#ifdef HAVE_FUTIMES
+      success = futimes (fd, tvp);
+#else
+      success = utimes (fname, tvp);
+#endif
+
+      if (success != 0)
 	{
 	  error (0, errno, gettext ("\
 cannot set access and modification date of '%s'"),
@@ -2144,7 +2151,14 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname,
 
   if (tvp != NULL)
     {
-      if (unlikely (futimes (fd, tvp) != 0))
+      int success;
+#ifdef HAVE_FUTIMES
+      success = futimes (fd, tvp);
+#else
+      success = utimes (fname, tvp);
+#endif
+
+      if (unlikely (success != 0))
 	{
 	  error (0, errno, gettext ("\
 cannot set access and modification date of '%s'"), fname);
-- 
1.8.1.4


             reply	other threads:[~2015-05-03 23:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03 23:25 Max Filippov [this message]
2015-05-04  5:58 Mike Frysinger
2015-05-04 12:58 Max Filippov
2015-05-04 14:16 Mark Wielaard
2015-05-05 19:26 Roland McGrath

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=1430695544-7336-4-git-send-email-jcmvbkbc@gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=elfutils-devel@lists.fedorahosted.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).