rewinddir.c 450 B

12345678910111213141516171819202122
  1. #include <dirent.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include "dirstream.h"
  5. /* rewinddir() just does an lseek(fd,0,0) - see close for comments */
  6. void rewinddir(DIR * dir)
  7. {
  8. if (!dir) {
  9. __set_errno(EBADF);
  10. return;
  11. }
  12. #ifdef _POSIX_THREADS
  13. pthread_mutex_lock(dir->dd_lock);
  14. #endif
  15. lseek(dir->dd_fd, 0, SEEK_SET);
  16. dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0;
  17. #ifdef _POSIX_THREADS
  18. pthread_mutex_unlock(dir->dd_lock);
  19. #endif
  20. }