autoupdate
[gnulib.git] / m4 / utime.m4
1 # serial 9
2
3 dnl From Jim Meyering
4 dnl Replace the utime function on systems that need it.
5
6 # Copyright (C) 1998, 2000-2001, 2003-2004, 2009 Free Software Foundation, Inc.
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10
11 dnl FIXME
12
13 AC_DEFUN([gl_FUNC_UTIME],
14 [
15   AC_REQUIRE([AC_FUNC_UTIME_NULL])
16   if test $ac_cv_func_utime_null = no; then
17     AC_LIBOBJ([utime])
18     AC_DEFINE([utime], [rpl_utime],
19       [Define to rpl_utime if the replacement function should be used.])
20     gl_PREREQ_UTIME
21   fi
22 ])
23
24 # Prerequisites of lib/utime.c.
25 AC_DEFUN([gl_PREREQ_UTIME],
26 [
27   AC_CHECK_HEADERS_ONCE([utime.h])
28   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
29   gl_FUNC_UTIMES_NULL
30 ])
31
32 # Use the definition of AC_FUNC_UTIME_NULL from autoconf 2.64 or newer.
33 # Remove this macro when we can assume autoconf >= 2.64.
34 m4_version_prereq([2.64], [], [
35 AC_DEFUN([AC_FUNC_UTIME_NULL],
36 [AC_CHECK_HEADERS_ONCE([utime.h])
37 AC_CACHE_CHECK([whether utime accepts a null argument], [ac_cv_func_utime_null],
38 [rm -f conftest.data; >conftest.data
39 # Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
40 AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
41                #ifdef HAVE_UTIME_H
42                # include <utime.h>
43                #endif],
44 [[struct stat s, t;
45   return ! (stat ("conftest.data", &s) == 0
46             && utime ("conftest.data", 0) == 0
47             && stat ("conftest.data", &t) == 0
48             && t.st_mtime >= s.st_mtime
49             && t.st_mtime - s.st_mtime < 120);]])],
50               ac_cv_func_utime_null=yes,
51               ac_cv_func_utime_null=no,
52               ac_cv_func_utime_null='guessing yes')])
53 if test "x$ac_cv_func_utime_null" != xno; then
54   ac_cv_func_utime_null=yes
55   AC_DEFINE([HAVE_UTIME_NULL], [1],
56             [Define to 1 if `utime(file, NULL)' sets file's timestamp to the
57              present.])
58 fi
59 rm -f conftest.data
60 ])
61 ])