Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / misc / rewinddir.c
1 /*
2         rewinddir -- rewind a directory stream
3
4         last edit:      25-Apr-1987     D A Gwyn
5
6         This is not simply a call to seekdir(), because seekdir()
7         will use the current buffer whenever possible and we need
8         rewinddir() to forget about buffered data.
9 */
10
11 #include        <errno.h>
12 #include        <sys/errno.h>
13 #include        <sys/types.h>
14 #include        <dirent.h>
15
16 extern off_t    _lseek(int d, int offset, int whence);
17
18 #ifndef NULL
19 #define NULL    0
20 #endif
21
22 #ifndef SEEK_SET
23 #define SEEK_SET        0
24 #endif
25
26 void
27 rewinddir(register DIR *dirp)
28 {
29         if ( dirp == NULL || dirp->dd_buf == NULL )
30                 {
31                 errno = EFAULT;
32                 return;                 /* invalid pointer */
33                 }
34
35         dirp->dd_loc = dirp->dd_size = 0;       /* invalidate buffer */
36         (void)_lseek( dirp->dd_fd, (off_t)0, SEEK_SET );        /* may set errno */
37 }