From 7f9a782c210d5a07bb9c73a54d389554cf5d4d70 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 8 Jun 2013 21:04:16 -0400 Subject: [PATCH 5/6] Fall back on utimes if futimes is not available 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 --- configure.ac | 3 +++ src/ar.c | 8 +++++++- src/strip.c | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 20fd3bc..3304510 100644 --- a/configure.ac +++ b/configure.ac @@ -268,6 +268,9 @@ AC_CHECK_FUNCS_ONCE([__mempcpy]) dnl Chekf for obstack_printf AC_CHECK_FUNCS_ONCE([obstack_printf]) +dnl Check for futimes +AC_CHECK_FUNC([futimes]) + dnl The directories with content. dnl Documentation. diff --git a/src/ar.c b/src/ar.c index f6d5823..f31329d 100644 --- a/src/ar.c +++ b/src/ar.c @@ -693,7 +693,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 c4c1f35..5180d75 100644 --- a/src/strip.c +++ b/src/strip.c @@ -2061,10 +2061,17 @@ while computing checksum for debug information")); close (debug_fd); } + int success; +#ifdef HAVE_FUTIMES + success = futimes (fd, tvp); +#else + success = utimes (fname, tvp); +#endif + /* If requested, preserve the timestamp. */ if (tvp != NULL) { - if (futimes (fd, tvp) != 0) + if (success != 0) { error (0, errno, gettext ("\ cannot set access and modification date of '%s'"), @@ -2119,9 +2126,16 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, INTERNAL_ERROR (fname); } + int success; +#ifdef HAVE_FUTIMES + success = futimes (fd, tvp); +#else + success = utimes (fname, tvp); +#endif + if (tvp != NULL) { - if (unlikely (futimes (fd, tvp) != 0)) + if (unlikely (success != 0)) { error (0, errno, gettext ("\ cannot set access and modification date of '%s'"), fname); -- 1.7.8.6