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

Defined functions

closedir defined in line 112; used 2 times
opendir defined in line 37; used 2 times
readdir defined in line 78; used 3 times

Defined struct's

olddirect defined in line 68; used 6 times

Defined macros

ODIRSIZ defined in line 66; used 4 times
Last modified: 1987-06-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2850
Valid CSS Valid XHTML 1.0 Strict