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(). */
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. */
#endif /* !WINDOWS_SOCKETS */
+ if (saved_errno != 0)
+ {
+ errno = saved_errno;
+ result = EOF;
+ }
+
return result;
}