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