home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume9 / gwyn-dir-lib / telldir.c < prev    next >
C/C++ Source or Header  |  1987-04-30  |  794b  |  37 lines

  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    <sys/errno.h>
  11. #include    <sys/types.h>
  12. #include    <dirent.h>
  13.  
  14. extern off_t    lseek();
  15.  
  16. extern int    errno;
  17.  
  18. #ifndef SEEK_CUR
  19. #define    SEEK_CUR    1
  20. #endif
  21.  
  22. off_t
  23. telldir( dirp )                /* return offset of next entry */
  24.     DIR    *dirp;            /* stream from opendir() */
  25.     {
  26.     if ( dirp == NULL || dirp->dd_buf == NULL )
  27.         {
  28.         errno = EFAULT;
  29.         return -1;        /* invalid pointer */
  30.         }
  31.  
  32.     if ( dirp->dd_loc < dirp->dd_size )    /* valid index */
  33.         return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
  34.     else                /* beginning of next directory block */
  35.         return lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
  36.     }
  37.