Import upstream version 1.29
[debian/tar] / gnu / fcntl.c
index c272ec9c754bd1471767ba73e3390ad2e3ee673e..23b73e975c844d976a032d2582f482fac0f43f33 100644 (file)
@@ -1,8 +1,6 @@
-/* -*- buffer-read-only: t -*- vi: set ro: */
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 /* Provide file descriptor control.
 
-   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -91,8 +89,25 @@ dupfd (int oldfd, int newfd, int flags)
                             inherit,                /* InheritHandle */
                             DUPLICATE_SAME_ACCESS)) /* Options */
         {
-          /* TODO: Translate GetLastError () into errno.  */
-          errno = EMFILE;
+          switch (GetLastError ())
+            {
+              case ERROR_TOO_MANY_OPEN_FILES:
+                errno = EMFILE;
+                break;
+              case ERROR_INVALID_HANDLE:
+              case ERROR_INVALID_TARGET_HANDLE:
+              case ERROR_DIRECT_ACCESS_HANDLE:
+                errno = EBADF;
+                break;
+              case ERROR_INVALID_PARAMETER:
+              case ERROR_INVALID_FUNCTION:
+              case ERROR_INVALID_ACCESS:
+                errno = EINVAL;
+                break;
+              default:
+                errno = EACCES;
+                break;
+            }
           result = -1;
           break;
         }
@@ -100,7 +115,6 @@ dupfd (int oldfd, int newfd, int flags)
       if (duplicated_fd < 0)
         {
           CloseHandle (new_handle);
-          errno = EMFILE;
           result = -1;
           break;
         }