changeset 18213:8e15c249e138

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.
author KO Myung-Hun <komh@chollian.net>
date Fri, 28 Nov 2014 16:43:14 +0900
parents 5926b8112df9
children 582ba937cae1
files ChangeLog doc/posix-functions/utimes.texi m4/utimes.m4
diffstat 3 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jan 17 18:54:05 2015 +0900
+++ b/ChangeLog	Fri Nov 28 16:43:14 2014 +0900
@@ -1,3 +1,14 @@
+2016-01-15  KO Myung-Hun  <komh@chollian.net>
+
+	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  <eggert@cs.ucla.edu>
             KO Myung-Hun  <komh@chollian.net>
 
--- a/doc/posix-functions/utimes.texi	Sat Jan 17 18:54:05 2015 +0900
+++ b/doc/posix-functions/utimes.texi	Fri Nov 28 16:43:14 2014 +0900
@@ -35,6 +35,14 @@
 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
--- a/m4/utimes.m4	Sat Jan 17 18:54:05 2015 +0900
+++ b/m4/utimes.m4	Fri Nov 28 16:43:14 2014 +0900
@@ -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 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <utime.h>
+#include <errno.h>
 
 static int
 inorder (time_t a, time_t b, time_t c)
@@ -45,7 +46,10 @@
 {
   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 @@
           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;