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

34 lines
777 B
C
Raw Normal View History

1989-12-18 14:40:54 +00:00
/*
telldir -- report directory stream position
last edit: 25-Apr-1987 D A Gwyn
NOTE: 4.nBSD directory compaction makes seekdir() & telldir()
practically impossible to do right. Avoid using them!
*/
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
extern off_t _lseek(int d, int offset, int whence);
1989-12-18 14:40:54 +00:00
#ifndef SEEK_CUR
2018-06-21 20:33:47 +00:00
#define SEEK_CUR 1
1989-12-18 14:40:54 +00:00
#endif
2018-06-21 20:33:47 +00:00
off_t telldir(register DIR* dirp) /* return offset of next entry */
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 -1; /* invalid pointer */
}
1989-12-18 14:40:54 +00:00
2018-06-21 20:33:47 +00:00
if (dirp->dd_loc < dirp->dd_size) /* valid index */
return ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off;
else /* beginning of next directory block */
return _lseek(dirp->dd_fd, (off_t)0, SEEK_CUR);
1989-12-18 14:40:54 +00:00
}