From: Paul Eggert Date: Sun, 17 Aug 2003 03:00:14 +0000 (+0000) Subject: utimes merge from coreutils X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=078bf4ac2813c5a3a93e5d57b5b42c3419aa63a0;p=pspp utimes merge from coreutils --- diff --git a/m4/utimes-null.m4 b/m4/utimes-null.m4 new file mode 100644 index 0000000000..f7e7842c5a --- /dev/null +++ b/m4/utimes-null.m4 @@ -0,0 +1,32 @@ +#serial 4 + +dnl Shamelessly cloned from acspecific.m4's AC_FUNC_UTIME_NULL, +dnl then do case-insensitive s/utime/utimes/. + +AC_DEFUN([jm_FUNC_UTIMES_NULL], +[AC_CACHE_CHECK(whether utimes accepts a null argument, ac_cv_func_utimes_null, +[rm -f conftest.data; > conftest.data +AC_TRY_RUN([ +/* In case stat has been defined to rpl_stat, undef it here. */ +#undef stat +#include +#include +main() { +struct stat s, t; +exit(!(stat ("conftest.data", &s) == 0 + && utimes("conftest.data", (long *)0) == 0 + && stat("conftest.data", &t) == 0 + && t.st_mtime >= s.st_mtime + && t.st_mtime - s.st_mtime < 120)); +}], + ac_cv_func_utimes_null=yes, + ac_cv_func_utimes_null=no, + ac_cv_func_utimes_null=no) +rm -f core core.* *.core]) + + if test $ac_cv_func_utimes_null = yes; then + AC_DEFINE(HAVE_UTIMES_NULL, 1, + [Define if utimes accepts a null argument]) + fi + ] +) diff --git a/m4/utimes.m4 b/m4/utimes.m4 index f7e7842c5a..3b8d945ac2 100644 --- a/m4/utimes.m4 +++ b/m4/utimes.m4 @@ -1,32 +1,46 @@ -#serial 4 +# See if we need to work around bugs in glibc's implementation of +# utimes from around July/August 2003. +# First, there was a bug that would make utimes set mtime +# and atime to zero (1970-01-01) unconditionally. +# Then, there is/was code to round rather than truncate. +# +# From Jim Meyering, with suggestions from Paul Eggert. -dnl Shamelessly cloned from acspecific.m4's AC_FUNC_UTIME_NULL, -dnl then do case-insensitive s/utime/utimes/. - -AC_DEFUN([jm_FUNC_UTIMES_NULL], -[AC_CACHE_CHECK(whether utimes accepts a null argument, ac_cv_func_utimes_null, -[rm -f conftest.data; > conftest.data -AC_TRY_RUN([ -/* In case stat has been defined to rpl_stat, undef it here. */ -#undef stat +AC_DEFUN([gl_FUNC_UTIMES], +[ + AC_CACHE_CHECK([determine whether the utimes function works], + gl_cv_func_working_utimes, + [ + AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include -main() { -struct stat s, t; -exit(!(stat ("conftest.data", &s) == 0 - && utimes("conftest.data", (long *)0) == 0 - && stat("conftest.data", &t) == 0 - && t.st_mtime >= s.st_mtime - && t.st_mtime - s.st_mtime < 120)); -}], - ac_cv_func_utimes_null=yes, - ac_cv_func_utimes_null=no, - ac_cv_func_utimes_null=no) -rm -f core core.* *.core]) +#include +#include +#include +#include +#include + +int +main () +{ + static struct timeval timeval[2] = {{9, 10}, {999999, 999999}}; + struct stat sbuf; + char const *file = "conftest.utimes"; + FILE *f; + + exit ( ! ((f = fopen (file, "w")) + && fclose (f) == 0 + && utimes (file, timeval) == 0 + && lstat (file, &sbuf) == 0 + && sbuf.st_atime == timeval[0].tv_sec + && sbuf.st_mtime == timeval[1].tv_sec) ); +} + ]])], + [gl_cv_func_working_utimes=yes], + [gl_cv_func_working_utimes=no], + [gl_cv_func_working_utimes=no])]) - if test $ac_cv_func_utimes_null = yes; then - AC_DEFINE(HAVE_UTIMES_NULL, 1, - [Define if utimes accepts a null argument]) - fi - ] -) + if test $gl_cv_func_working_utimes = yes; then + AC_DEFINE([HAVE_WORKING_UTIMES], 1, [Define if utimes works properly. ]) + fi +]) diff --git a/modules/utime b/modules/utime index c2db72edf6..a0d1ae3a47 100644 --- a/modules/utime +++ b/modules/utime @@ -4,8 +4,9 @@ utime() function: change access and/or modification times of a file. Files: lib/utime.c m4/utimbuf.m4 -m4/utimes.m4 m4/utime.m4 +m4/utimes.m4 +m4/utimes-null.m4 Depends-on: safe-read