From: "Anthony G. Basile" <[email protected]>

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 <[email protected]>
[Max: move futimes/utimes in strip.c into 'if (tvp != NULL)' blocks.]
Signed-off-by: Max Filippov <[email protected]>
---
 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  <[email protected]>
 
+       * configure.ac (futimes): Check if function exists.
+
+2015-05-04  Anthony G. Basile  <[email protected]>
+
        * 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  <[email protected]>
+
+       * 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  <[email protected]>
 
        * 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 via email to