ack/lang/cem/libcc.ansi/misc/rewinddir.c

37 lines
729 B
C
Raw Normal View History

1989-12-18 14:40:54 +00:00
/*
rewinddir -- rewind a directory stream
last edit: 25-Apr-1987 D A Gwyn
This is not simply a call to seekdir(), because seekdir()
will use the current buffer whenever possible and we need
rewinddir() to forget about buffered data.
*/
2018-06-21 20:33:47 +00:00
#include <errno.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <dirent.h>
1989-12-18 14:40:54 +00:00
2018-06-21 20:33:47 +00:00
extern off_t _lseek(int d, int offset, int whence);
1989-12-18 14:40:54 +00:00
#ifndef NULL
2018-06-21 20:33:47 +00:00
#define NULL 0
1989-12-18 14:40:54 +00:00
#endif
#ifndef SEEK_SET
2018-06-21 20:33:47 +00:00
#define SEEK_SET 0
1989-12-18 14:40:54 +00:00
#endif
2018-06-21 20:33:47 +00:00
void rewinddir(register DIR* dirp)
1989-12-18 14:40:54 +00:00
{
2018-06-21 20:33:47 +00:00
if (dirp == NULL || dirp->dd_buf == NULL)
{
1989-12-18 14:40:54 +00:00
errno = EFAULT;
2018-06-21 20:33:47 +00:00
return; /* invalid pointer */
}
1989-12-18 14:40:54 +00:00
2018-06-21 20:33:47 +00:00
dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
(void)_lseek(dirp->dd_fd, (off_t)0, SEEK_SET); /* may set errno */
1989-12-18 14:40:54 +00:00
}