strerror: drop strerror_r dependency
[gnulib.git] / lib / fclose.c
index a8d68b4..27f6836 100644 (file)
@@ -57,12 +57,6 @@ rpl_fclose (FILE *fp)
 
   fclose (fp); /* will fail with errno = EBADF, if we did not lose a race */
 
-  if (saved_errno != 0)
-    {
-      errno = saved_errno;
-      result = EOF;
-    }
-
 #else /* !WINDOWS_SOCKETS */
   /* Call fclose() and invoke all hooks of the overridden close().  */
 
@@ -71,7 +65,7 @@ rpl_fclose (FILE *fp)
      Some other thread could open fd between our calls to fclose and
      _gl_unregister_fd.  */
   result = fclose (fp);
-  if (result >= 0)
+  if (result == 0)
     _gl_unregister_fd (fd);
 # else
   /* No race condition here.  */
@@ -80,5 +74,11 @@ rpl_fclose (FILE *fp)
 
 #endif /* !WINDOWS_SOCKETS */
 
+  if (saved_errno != 0)
+    {
+      errno = saved_errno;
+      result = EOF;
+    }
+
   return result;
 }