From 5e3c9b55f2a813e41f7f33f48c33db054a17e608 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 25 Aug 2011 11:41:51 +0200 Subject: [PATCH] Prefers utime over futimens when available. --- ChangeLog | 4 ++++ configure.ac | 2 +- src/ChangeLog | 7 +++++++ src/utils.c | 29 ++++++++++++++++++++++++++--- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6372d51e..b461e939 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-08-25 Giuseppe Scrivano + + * configure.ac: Check for `utime'. + 2011-08-11 Giuseppe Scrivano * bootstrap.conf (gnulib_modules): Add `sigprocmask'. diff --git a/configure.ac b/configure.ac index b9ccbfef..c26c93ec 100644 --- a/configure.ac +++ b/configure.ac @@ -197,7 +197,7 @@ AC_FUNC_MMAP AC_FUNC_FSEEKO AC_CHECK_FUNCS(strptime timegm vsnprintf vasprintf drand48) AC_CHECK_FUNCS(strtoll usleep ftello sigblock sigsetjmp memrchr wcwidth mbtowc) -AC_CHECK_FUNCS(sleep symlink) +AC_CHECK_FUNCS(sleep symlink utime) if test x"$ENABLE_OPIE" = xyes; then AC_LIBOBJ([ftp-opie]) diff --git a/src/ChangeLog b/src/ChangeLog index 8e9572f2..fe03b7bf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-08-25 Giuseppe Scrivano + + * utils.c [HAVE_UTIME && HAVE_UTIME_H]: Include . + [HAVE_UTIME && HAVE_SYS_UTIME_H]: Include . + (touch) [HAVE_UTIME: Prefers utime over futimens when it is available. + It was reported that Cygwin has a not working futimens. + 2011-08-19 Giuseppe Scrivano * init.c (home_dir) [MSDOS]: Move local variable `len' here. diff --git a/src/utils.c b/src/utils.c index 7d4834fb..4950ab2e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -42,15 +42,23 @@ as that of the covered work. */ #ifdef HAVE_PROCESS_H # include /* getpid() */ #endif -#ifdef HAVE_UTIME_H -# include -#endif #include #include #include #include #include +#if HAVE_UTIME +# include +# ifdef HAVE_UTIME_H +# include +# endif + +# ifdef HAVE_SYS_UTIME_H +# include +# endif +#endif + #include /* For TIOCGWINSZ and friends: */ @@ -487,6 +495,20 @@ fork_to_background (void) void touch (const char *file, time_t tm) { +#if HAVE_UTIME +# ifdef HAVE_STRUCT_UTIMBUF + struct utimbuf times; +# else + struct { + time_t actime; + time_t modtime; + } times; +# endif + times.modtime = tm; + times.actime = time (NULL); + if (utime (file, ×) == -1) + logprintf (LOG_NOTQUIET, "utime(%s): %s\n", file, strerror (errno)); +#else struct timespec timespecs[2]; int fd; @@ -506,6 +528,7 @@ touch (const char *file, time_t tm) logprintf (LOG_NOTQUIET, "futimens(%s): %s\n", file, strerror (errno)); close (fd); +#endif } /* Checks if FILE is a symbolic link, and removes it if it is. Does -- 2.39.2