Paul Eggert wrote: > On 01/13/2016 06:23 PM, KO Myung-Hun wrote: >> +@item >> +On OS/2, this funciton cannot set timestamp earlier than 1980 year in >> local >> +time. >> +@item >> +On OS/2, this function cannot set timestamp in odd seconds. > > Misspelled "function", and some grammar issues. Please change to > something like this: > > 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. > > >> + /* On OS/2, a file date should be since 1980 year in local time >> + and even seconds. */ > > Reword to "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,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) > > This doesn't look right, as the original order of updating the file's > time stamps is needed to tickle the NFS bug. Instead, please change the > code to attempt utimes() on the opened file, and if this fails the way > that kLIBC fails, then close the file, invoke utimes on the file, and > reopen the file. That way, the order will be preserved and there should > be no need for any EBADF check.
Updated. -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr
From c1947fc85a69035d088f9c5355228c2ab39cb218 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun <komh@chollian.net> 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. --- doc/posix-functions/utimes.texi | 8 ++++++++ m4/utimes.m4 | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/posix-functions/utimes.texi b/doc/posix-functions/utimes.texi index 0db82c9..e9bf272 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 a016723..955e77d 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 <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, 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 + /* utimes() of OS/2 kLIBC does not work on an opend file. */ + || close (fd) != 0 + || utimes (file, timeval) != 0 + || (fd = open (file, O_WRONLY, 0644)) < 0)) result |= 2; - else if (utimes (file, NULL) != 0) + else if (utimes (file, NULL) != 0 + && (errno != EACCES + /* utimes() of OS/2 kLIBC does not work on an opend file. */ + || close (fd) != 0 + || utimes (file, NULL) != 0 + || (fd = open (file, O_WRONLY, 0644)) < 0)) result |= 8; else if (fstat (fd, &st1) != 0) result |= 1; -- 2.7.0