bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 10/11] utimes: detect utimes() correctly on OS/2 kLIBC


From: KO Myung-Hun
Subject: [PATCH 10/11] utimes: detect utimes() correctly on OS/2 kLIBC
Date: Wed, 22 Jul 2015 14:49:38 +0900

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/utime.texi: Document the above limitations of
utimes() on OS/2 kLIBC.
---
 doc/posix-functions/utime.texi |  7 +++++++
 m4/utimes.m4                   | 24 ++++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/doc/posix-functions/utime.texi b/doc/posix-functions/utime.texi
index 9cfe373..a0fb67d 100644
--- a/doc/posix-functions/utime.texi
+++ b/doc/posix-functions/utime.texi
@@ -27,4 +27,11 @@ On some platforms, the prototype for @code{utime} omits 
@code{const}
 for the second argument.  Fortunately, the argument is not modified,
 so it is safe to cast away const:
 mingw, MSVC 9.
address@hidden
+On OS/2, this funciton cannot set timestamp earlier than 1980 year in local
+time.
address@hidden
+On OS/2, this function cannot set timestamp in odd seconds.
address@hidden
+On OS/2, this function does not work on an opened file.
 @end itemize
diff --git a/m4/utimes.m4 b/m4/utimes.m4
index e26a576..45d9c69 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-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
@@ -33,6 +33,7 @@ AC_DEFUN([gl_FUNC_UTIMES],
 #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 @@ main ()
 {
   int result = 0;
   char const *file = "conftest.utimes";
-  static struct timeval timeval[2] = {{9, 10}, {999999, 999999}};
+  /* On OS/2, a file date should be since 1980 year in local time
+     and even seconds.  */
+  static struct timeval timeval[2] = {{315620000 + 10, 10},
+                                      {315620000 + 1000000, 999998}};
 
   /* Test whether utimes() essentially works.  */
   {
@@ -82,15 +86,18 @@ main ()
           result |= 1;
         else if (fstat (fd, &st0) != 0)
           result |= 1;
+        else if (write (fd, "\n", 1) != 1)
+          result |= 1;
+        else if (fstat (fd, &st1) != 0)
+          result |= 1;
+        /* utimes() of OS/2 kLIBC does not work on an opened file */
+        else if (close (fd) != 0)
+          result |= 1;
         else if (utimes (file, timeval) != 0)
           result |= 2;
         else if (utimes (file, NULL) != 0)
           result |= 8;
-        else if (fstat (fd, &st1) != 0)
-          result |= 1;
-        else if (write (fd, "\n", 1) != 1)
-          result |= 1;
-        else if (fstat (fd, &st2) != 0)
+        else if (lstat (file, &st2) != 0)
           result |= 1;
         else if (time (&t2) == (time_t) -1)
           result |= 1;
@@ -103,7 +110,8 @@ main ()
             if (! (m_ok_POSIX || m_ok_NFS))
               result |= 32;
           }
-        if (close (fd) != 0)
+        /* Ensure to close fd, but ignore an error if already closed. */
+        if (close (fd) != 0 && errno != EBADF)
           result |= 1;
       }
     if (unlink (file) != 0)
-- 
1.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]