From 8968c785d7bc4c7578070ad2ce6e7a82bcca8b3d Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Fri, 28 Nov 2014 16:43:14 +0900 Subject: [PATCH] utimes: detect utimes() correctly on OS/2 kLIBC utimes() of OS/2 kLIBC has some limitations. 1. OS/2 itself supports a file date since 1980 year in local time. 2. OS/2 itself supports only even seconds for a file time. 3. utimes() of OS/2 kLIBC does not work on an opened file. * m4/utimes.m4: Detect utimes() correctly on OS/2 kLIBC. * doc/posix-functions/utimes.texi: Document the above limitations of utimes() on OS/2 kLIBC. --- ChangeLog | 11 +++++++++++ doc/posix-functions/utimes.texi | 8 ++++++++ m4/utimes.m4 | 22 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a5aed6979..5bedafaf0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2016-01-15 KO Myung-Hun + + utimes: detect utimes() correctly on OS/2 kLIBC + utimes() of OS/2 kLIBC has some limitations. + 1. OS/2 itself supports a file date since 1980 year in local time. + 2. OS/2 itself supports only even seconds for a file time. + 3. utimes() of OS/2 kLIBC does not work on an opened file. + * m4/utimes.m4: Detect utimes() correctly on OS/2 kLIBC. + * doc/posix-functions/utimes.texi: Document the above limitations of + utimes() on OS/2 kLIBC. + 2016-01-15 Paul Eggert KO Myung-Hun diff --git a/doc/posix-functions/utimes.texi b/doc/posix-functions/utimes.texi index 0db82c974a..e9bf2726e0 100644 --- a/doc/posix-functions/utimes.texi +++ b/doc/posix-functions/utimes.texi @@ -35,6 +35,14 @@ glibc 2.3.3. On some platforms, @code{utimes} failed on read-only files when @code{utime} worked fine. glibc 2.2.5. +@item +On OS/2, this function cannot set the timestamp to earlier than the +year 1980 in local time. +@item +On OS/2, this function cannot set the timestamp to an odd number of +seconds. +@item +On OS/2, this function does not work on an opened file. @end itemize Extension: Gnulib provides a module @samp{utimens} that works around these diff --git a/m4/utimes.m4 b/m4/utimes.m4 index a016723e24..1876bec799 100644 --- a/m4/utimes.m4 +++ b/m4/utimes.m4 @@ -1,5 +1,5 @@ # Detect some bugs in glibc's implementation of utimes. -# serial 3 +# serial 4 dnl Copyright (C) 2003-2005, 2009-2016 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -33,6 +33,7 @@ AC_DEFUN([gl_FUNC_UTIMES], #include #include #include +#include static int inorder (time_t a, time_t b, time_t c) @@ -45,7 +46,10 @@ main () { int result = 0; char const *file = "conftest.utimes"; - static struct timeval timeval[2] = {{9, 10}, {999999, 999999}}; + /* On OS/2, file timestamps must be on or after 1980 in local time, + with an even number of seconds. */ + static struct timeval timeval[2] = {{315620000 + 10, 10}, + {315620000 + 1000000, 999998}}; /* Test whether utimes() essentially works. */ { @@ -82,9 +86,19 @@ main () result |= 1; else if (fstat (fd, &st0) != 0) result |= 1; - else if (utimes (file, timeval) != 0) + else if (utimes (file, timeval) != 0 + && (errno != EACCES + /* OS/2 kLIBC utimes fails on opened files. */ + || close (fd) != 0 + || utimes (file, timeval) != 0 + || (fd = open (file, O_WRONLY)) < 0)) result |= 2; - else if (utimes (file, NULL) != 0) + else if (utimes (file, NULL) != 0 + && (errno != EACCES + /* OS/2 kLIBC utimes fails on opened files. */ + || close (fd) != 0 + || utimes (file, NULL) != 0 + || (fd = open (file, O_WRONLY)) < 0)) result |= 8; else if (fstat (fd, &st1) != 0) result |= 1; -- 2.39.5