]> Savannah Git Hosting - gnulib.git/commitdiff
utimens: Improve error code on native Windows.
authorBruno Haible <bruno@clisp.org>
Sun, 7 May 2017 19:19:13 +0000 (21:19 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 8 May 2017 09:58:49 +0000 (11:58 +0200)
* lib/utimens.c (fdutimens): If fd was not opened with O_RDWR, fail with
error code EACCES, not EINVAL.

ChangeLog
lib/utimens.c

index 75537dcaf59d82e0bae6cf78c572c9007aa94c3c..1fbcd8fccf30c432e493f36340574386d049ff65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-07 Bruno Haible  <bruno@clisp.org>
+
+       utimens: Improve error code on native Windows.
+       * lib/utimens.c (fdutimens): If fd was not opened with O_RDWR, fail with
+       error code EACCES, not EINVAL.
+
 2017-05-07 Bruno Haible  <bruno@clisp.org>
 
        utime: Handle more Windows error codes.
index 5f3a846ea2f6edd24b0b0aa1952df754524ed6e6..b027cfb673115e82fc54ca9f8665c3496de6ee88 100644 (file)
@@ -349,11 +349,19 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
         return 0;
       else
         {
-          #if 0
           DWORD sft_error = GetLastError ();
-          fprintf (stderr, "utime SetFileTime error 0x%x\n", (unsigned int) sft_error);
+          #if 0
+          fprintf (stderr, "fdutimens SetFileTime error 0x%x\n", (unsigned int) sft_error);
           #endif
-          errno = EINVAL;
+          switch (sft_error)
+            {
+            case ERROR_ACCESS_DENIED: /* fd was opened without O_RDWR */
+              errno = EACCES; /* not specified by POSIX */
+              break;
+            default:
+              errno = EINVAL;
+              break;
+            }
           return -1;
         }
     }