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: 
  38:     if ((fd = open(name, 0)) == -1)
  39:         return NULL;
  40:     if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
  41:         close (fd);
  42:         return NULL;
  43:     }
  44:     dirp->dd_fd = fd;
  45:     dirp->dd_loc = 0;
  46:     return dirp;
  47: }
  48: 
  49: /*
  50:  * read an old style directory entry and present it as a new one
  51:  */
  52: #ifndef pyr
  53: #define ODIRSIZ 14
  54: 
  55: struct  olddirect {
  56:     ino_t   od_ino;
  57:     char    od_name[ODIRSIZ];
  58: };
  59: #else   an Pyramid in the ATT universe
  60: #define ODIRSIZ 248
  61: 
  62: struct  olddirect {
  63:     long    od_ino;
  64:     short   od_fill1, od_fill2;
  65:     char    od_name[ODIRSIZ];
  66: };
  67: #endif
  68: 
  69: /*
  70:  * get next entry in a directory.
  71:  */
  72: struct direct *
  73: readdir(dirp)
  74: register DIR *dirp;
  75: {
  76:     register struct olddirect *dp;
  77:     static struct direct dir;
  78: 
  79:     for (;;) {
  80:         if (dirp->dd_loc == 0) {
  81:             dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
  82:                 DIRBLKSIZ);
  83:             if (dirp->dd_size <= 0)
  84:                 return NULL;
  85:         }
  86:         if (dirp->dd_loc >= dirp->dd_size) {
  87:             dirp->dd_loc = 0;
  88:             continue;
  89:         }
  90:         dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
  91:         dirp->dd_loc += sizeof(struct olddirect);
  92:         if (dp->od_ino == 0)
  93:             continue;
  94:         dir.d_ino = dp->od_ino;
  95:         strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  96:         dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
  97:         dir.d_namlen = strlen(dir.d_name);
  98:         dir.d_reclen = DIRSIZ(&dir);
  99:         return (&dir);
 100:     }
 101: }
 102: 
 103: /*
 104:  * close a directory.
 105:  */
 106: void
 107: closedir(dirp)
 108: register DIR *dirp;
 109: {
 110:     close(dirp->dd_fd);
 111:     dirp->dd_fd = -1;
 112:     dirp->dd_loc = 0;
 113:     free(dirp);
 114: }
 115: #endif USENDIR

Defined functions

closedir defined in line 106; used 3 times
opendir defined in line 31; used 3 times
readdir defined in line 72; used 4 times

Defined struct's

olddirect defined in line 62; used 6 times

Defined macros

ODIRSIZ defined in line 60; used 4 times
Last modified: 1985-06-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 561
Valid CSS Valid XHTML 1.0 Strict