Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / misc / telldir.c
1 /*
2         telldir -- report directory stream position
3
4         last edit:      25-Apr-1987     D A Gwyn
5
6         NOTE:   4.nBSD directory compaction makes seekdir() & telldir()
7                 practically impossible to do right.  Avoid using them!
8 */
9
10 #include        <errno.h>
11 #include        <sys/errno.h>
12 #include        <sys/types.h>
13 #include        <dirent.h>
14
15 extern off_t _lseek(int d, int offset, int whence);
16
17 #ifndef SEEK_CUR
18 #define SEEK_CUR        1
19 #endif
20
21 off_t
22 telldir(register DIR *dirp)             /* return offset of next entry */
23 {
24         if ( dirp == NULL || dirp->dd_buf == NULL )
25                 {
26                 errno = EFAULT;
27                 return -1;              /* invalid pointer */
28                 }
29
30         if ( dirp->dd_loc < dirp->dd_size )     /* valid index */
31                 return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
32         else                            /* beginning of next directory block */
33                 return _lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
34 }