Annotation of coherent/b/lib/libc/ndir/readdir.c, revision 1.1

1.1     ! root        1: /*
        !             2:        readdir -- read next entry from a directory stream
        !             3: 
        !             4:        last edit:      25-Apr-1987     D A Gwyn
        !             5: */
        !             6: 
        !             7: #ifdef COHERENT
        !             8: #include       <errno.h>
        !             9: #else
        !            10: #include       <sys/errno.h>
        !            11: #endif
        !            12: 
        !            13: #include       <sys/types.h>
        !            14: #include       "dirent.h"
        !            15: 
        !            16: extern int     getdents();             /* SVR3 system call, or emulation */
        !            17: 
        !            18: extern int     errno;
        !            19: 
        !            20: #ifndef NULL
        !            21: #define        NULL    0
        !            22: #endif
        !            23: 
        !            24: 
        !            25: struct dirent *
        !            26: readdir( dirp )
        !            27:        register DIR            *dirp;  /* stream from opendir() */
        !            28:        {
        !            29:        register struct dirent  *dp;    /* -> directory data */
        !            30: 
        !            31: #if DBG
        !            32:        printf("In readdir(dirp = %x, buffer= %x\n",(int) dirp,dirp->dd_buf);
        !            33:        printf("fd= %d; loc= %d; size=%d.",dirp->dd_fd,dirp->dd_loc,dirp->dd_size);
        !            34: 
        !            35: #endif
        !            36:        if ( dirp == NULL || dirp->dd_buf == NULL )
        !            37:                {
        !            38:                errno = EFAULT;
        !            39:                return NULL;            /* invalid pointer */
        !            40:                }
        !            41: 
        !            42:        do      {
        !            43:                if ( dirp->dd_loc >= dirp->dd_size )    /* empty or obsolete */
        !            44:                        dirp->dd_loc = dirp->dd_size = 0;
        !            45: 
        !            46:                if ( dirp->dd_size == 0 /* need to refill buffer */
        !            47:                  && (dirp->dd_size =
        !            48:                        getdents( dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF )
        !            49: 
        !            50:                     ) <= 0
        !            51:                   )
        !            52: 
        !            53:                        return NULL;    /* EOF or error */
        !            54: #if DBG
        !            55:        printf("dirp is good.\n");
        !            56: #endif
        !            57: 
        !            58:                dp = (struct dirent *) (&(dirp->dd_buf[dirp->dd_loc]));
        !            59: #if DBG
        !            60:        printf("buffer = %x, ptr = %x\n",dirp->dd_buf, dp);
        !            61: #endif
        !            62:                dirp->dd_loc += dp->d_reclen;
        !            63: #ifdef DBG
        !            64:        printf("readdir: dir. buffer loc= %d\n",dirp->dd_loc);
        !            65:        printf("\tinode = %D\n",dp->d_ino);
        !            66: #endif
        !            67:                }
        !            68:        while ( dp->d_ino == 0L );      /* don't rely on getdents() */
        !            69: 
        !            70: #if DBG
        !            71: printf ("readdir: name: %s; inode %D; offset %D; reclen %d\n",dp->d_name,
        !            72:        dp->d_ino, dp->d_off, dp->d_reclen);
        !            73: #endif
        !            74:        return dp;
        !            75:        }
        !            76: 
        !            77: 
        !            78: 
        !            79: 
        !            80: 
        !            81: 
        !            82: 
        !            83: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.