1: /* $Header: ndir.c,v 4.3.1.3 85/05/23 11:19:24 lwall Exp $
   2:  *
   3:  * $Log:	ndir.c,v $
   4:  * Revision 4.3.1.3  85/05/23  11:19:24  lwall
   5:  * Oops, shouldn't have included sys/types.h again.
   6:  *
   7:  * Revision 4.3.1.2  85/05/15  14:46:00  lwall
   8:  * Changed short to ino_t, which may be ushort on some systems.
   9:  *
  10:  * Revision 4.3.1.1  85/05/10  11:35:34  lwall
  11:  * Branch for patches.
  12:  *
  13:  * Revision 4.3  85/05/01  11:42:55  lwall
  14:  * Baseline for release with 4.3bsd.
  15:  *
  16:  */
  17: 
  18: #include "EXTERN.h"
  19: #include "common.h"
  20: #include "INTERN.h"
  21: #include "ndir.h"
  22: 
  23: #ifdef USENDIR
  24: /*
  25:  * support for Berkeley directory reading routine on a V7 file system
  26:  */
  27: 
  28: /*
  29:  * open a directory.
  30:  */
  31: DIR *
  32: opendir(name)
  33: char *name;
  34: {
  35:     register DIR *dirp;
  36:     register int fd;
  37:     char *malloc();
  38: 
  39:     if ((fd = open(name, 0)) == -1)
  40:         return NULL;
  41:     if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
  42:         close (fd);
  43:         return NULL;
  44:     }
  45:     dirp->dd_fd = fd;
  46:     dirp->dd_loc = 0;
  47:     return dirp;
  48: }
  49: 
  50: /*
  51:  * read an old style directory entry and present it as a new one
  52:  */
  53: #ifndef pyr
  54: #define ODIRSIZ 14
  55: 
  56: struct  olddirect {
  57:     ino_t   od_ino;
  58:     char    od_name[ODIRSIZ];
  59: };
  60: #else   an Pyramid in the ATT universe
  61: #define ODIRSIZ 248
  62: 
  63: struct  olddirect {
  64:     long    od_ino;
  65:     short   od_fill1, od_fill2;
  66:     char    od_name[ODIRSIZ];
  67: };
  68: #endif
  69: 
  70: /*
  71:  * get next entry in a directory.
  72:  */
  73: struct direct *
  74: readdir(dirp)
  75: register DIR *dirp;
  76: {
  77:     register struct olddirect *dp;
  78:     static struct direct dir;
  79: 
  80:     for (;;) {
  81:         if (dirp->dd_loc == 0) {
  82:             dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
  83:                 DIRBLKSIZ);
  84:             if (dirp->dd_size <= 0)
  85:                 return NULL;
  86:         }
  87:         if (dirp->dd_loc >= dirp->dd_size) {
  88:             dirp->dd_loc = 0;
  89:             continue;
  90:         }
  91:         dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
  92:         dirp->dd_loc += sizeof(struct olddirect);
  93:         if (dp->od_ino == 0)
  94:             continue;
  95:         dir.d_ino = dp->od_ino;
  96:         strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  97:         dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
  98:         dir.d_namlen = strlen(dir.d_name);
  99:         dir.d_reclen = DIRSIZ(&dir);
 100:         return (&dir);
 101:     }
 102: }
 103: 
 104: /*
 105:  * close a directory.
 106:  */
 107: void
 108: closedir(dirp)
 109: register DIR *dirp;
 110: {
 111:     close(dirp->dd_fd);
 112:     dirp->dd_fd = -1;
 113:     dirp->dd_loc = 0;
 114:     free(dirp);
 115: }
 116: #endif USENDIR

Defined functions

closedir defined in line 107; used 3 times
opendir defined in line 31; used 3 times
readdir defined in line 73; used 4 times

Defined struct's

olddirect defined in line 63; used 6 times

Defined macros

ODIRSIZ defined in line 61; used 4 times
Last modified: 1987-03-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2515
Valid CSS Valid XHTML 1.0 Strict