closedir.c 511 B

1234567891011121314151617181920212223242526272829
  1. #include <dirent.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include "dirstream.h"
  6. int attribute_hidden __closedir(DIR * dir)
  7. {
  8. int fd;
  9. if (!dir) {
  10. __set_errno(EBADF);
  11. return -1;
  12. }
  13. /* We need to check dd_fd. */
  14. if (dir->dd_fd == -1) {
  15. __set_errno(EBADF);
  16. return -1;
  17. }
  18. __pthread_mutex_lock(&(dir->dd_lock));
  19. fd = dir->dd_fd;
  20. dir->dd_fd = -1;
  21. __pthread_mutex_unlock(&(dir->dd_lock));
  22. free(dir->dd_buf);
  23. free(dir);
  24. return __close(fd);
  25. }
  26. strong_alias(__closedir,closedir)