int closedir (DIR *dirp) { # if REPLACE_FCHDIR int fd = dirfd (dirp); # endif int retval; #if HAVE_CLOSEDIR # undef closedir retval = closedir (dirp); #else if (dirp->current != INVALID_HANDLE_VALUE) FindClose (dirp->current); free (dirp); retval = 0; #endif #if REPLACE_FCHDIR if (retval >= 0) _gl_unregister_fd (fd); #endif return retval; }
int rpl_fclose (FILE *fp) { int saved_errno = 0; int fd; int result = 0; /* Don't change behavior on memstreams. */ fd = fileno (fp); if (fd < 0) return fclose_nothrow (fp); /* We only need to flush the file if it is not reading or if it is seekable. This only guarantees the file position of input files if the fflush module is also in use. */ if ((!freading (fp) || lseek (fileno (fp), 0, SEEK_CUR) != -1) && fflush (fp)) saved_errno = errno; /* fclose() calls close(), but we need to also invoke all hooks that our overridden close() function invokes. See lib/close.c. */ #if WINDOWS_SOCKETS /* Call the overridden close(), then the original fclose(). Note about multithread-safety: There is a race condition where some other thread could open fd between our close and fclose. */ if (close (fd) < 0 && saved_errno == 0) saved_errno = errno; fclose_nothrow (fp); /* will fail with errno = EBADF, if we did not lose a race */ #else /* !WINDOWS_SOCKETS */ /* Call fclose() and invoke all hooks of the overridden close(). */ # if REPLACE_FCHDIR /* Note about multithread-safety: There is a race condition here as well. Some other thread could open fd between our calls to fclose and _gl_unregister_fd. */ result = fclose_nothrow (fp); if (result == 0) _gl_unregister_fd (fd); # else /* No race condition here. */ result = fclose_nothrow (fp); # endif #endif /* !WINDOWS_SOCKETS */ if (saved_errno != 0) { errno = saved_errno; result = EOF; } return result; }
int rpl_closedir (DIR *dp) #undef closedir { int fd = dirfd (dp); int retval = closedir (dp); if (retval >= 0) _gl_unregister_fd (fd); return retval; }
int rpl_close (int fd) { #if WINDOWS_SOCKETS int retval = execute_all_close_hooks (close_nothrow, fd); #else int retval = close_nothrow (fd); #endif #if REPLACE_FCHDIR if (retval >= 0) _gl_unregister_fd (fd); #endif return retval; }
/* Override close() to call into other gnulib modules: */ int rpl_close(int fd) { #if defined(WINDOWS_SOCKETS) && WINDOWS_SOCKETS int retval = execute_all_close_hooks(close_nothrow, fd); #else int retval = close_nothrow(fd); #endif /* WINDOWS_SOCKETS */ #if defined(REPLACE_FCHDIR) && REPLACE_FCHDIR if (retval >= 0) { _gl_unregister_fd(fd); } #endif /* REPLACE_FCHDIR */ return retval; }
int rpl_close (int fd) #undef close { #if HAVE__GL_CLOSE_FD_MAYBE_SOCKET int retval = _gl_close_fd_maybe_socket (fd); #else int retval = close (fd); #endif #ifdef FCHDIR_REPLACEMENT if (retval >= 0) _gl_unregister_fd (fd); #endif return retval; }