rewinddir.c 476 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 __UCLIBC_HAS_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 __UCLIBC_HAS_THREADS__
  18. __pthread_mutex_unlock(&(dir->dd_lock));
  19. #endif
  20. }