add new directory access routines
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 21 Apr 1982 09:56:21 +0000 (01:56 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 21 Apr 1982 09:56:21 +0000 (01:56 -0800)
SCCS-vsn: old/make/defs 4.3
SCCS-vsn: old/make/dosys.c 4.3
SCCS-vsn: old/make/files.c 4.4
SCCS-vsn: old/make/main.c 4.2

usr/src/old/make/defs
usr/src/old/make/dosys.c
usr/src/old/make/files.c
usr/src/old/make/main.c

index 3070963..e743862 100644 (file)
@@ -1,6 +1,8 @@
-/* defs 4.2 81/03/15 */
+/* defs 4.3 82/04/20 */
 #include <stdio.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <sys/param.h>
+#include <ndir.h>
 
 #define SHELLCOM "/bin/sh"
 
 
 #define SHELLCOM "/bin/sh"
 
@@ -111,13 +113,13 @@ struct pattern
        };
 extern struct pattern *firstpat;
 
        };
 extern struct pattern *firstpat;
 
-struct opendir
+struct dirhdr
        {
        {
-       struct opendir *nxtopendir;
-       FILE * dirfc;
+       struct dirhdr *nxtopendir;
+       DIR *dirfc;
        char *dirn;
        };
        char *dirn;
        };
-extern struct opendir *firstod;
+extern struct dirhdr *firstod;
 
 
 struct chain
 
 
 struct chain
index 160be61..df5dc3a 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)dosys.c     4.2 (Berkeley) 82/03/14";
+static char *sccsid = "@(#)dosys.c     4.3 (Berkeley) 82/04/20";
 #include "defs"
 #include <signal.h>
 
 #include "defs"
 #include <signal.h>
 
@@ -80,12 +80,13 @@ return(status);
 
 doclose()      /* Close open directory files before exec'ing */
 {
 
 doclose()      /* Close open directory files before exec'ing */
 {
-register struct opendir *od;
+register struct dirhdr *od;
 
 for (od = firstod; od; od = od->nxtopendir)
 
 for (od = firstod; od; od = od->nxtopendir)
-       if (od->dirfc != NULL)
-               /* fclose(od->dirfc); */
-               close(od->dirfc->_file);
+       if (od->dirfc != NULL) {
+               closedir(od->dirfc);
+               od->dirfc = NULL;
+       }
 }
 \f
 
 }
 \f
 
@@ -131,7 +132,6 @@ return( await() );
 \f
 #include <errno.h>
 
 \f
 #include <errno.h>
 
-#include <sys/types.h>
 #include <sys/stat.h>
 
 
 #include <sys/stat.h>
 
 
index f36331d..ca7da58 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)files.c     4.3 (Berkeley) 82/03/14";
+static char *sccsid = "@(#)files.c     4.4 (Berkeley) 82/04/20";
 /* UNIX DEPENDENT PROCEDURES */
 
 
 /* UNIX DEPENDENT PROCEDURES */
 
 
@@ -131,7 +131,6 @@ char *builtin[] =
        0 };
 \f
 #include "defs"
        0 };
 \f
 #include "defs"
-#include <sys/types.h>
 
 
 TIMETYPE exists(filename)
 
 
 TIMETYPE exists(filename)
@@ -167,9 +166,8 @@ return(t);
 
 \f
 
 
 \f
 
-#include <sys/dir.h>
-FSTATIC char n15[15];
-FSTATIC char *n15end   = &n15[14];
+FSTATIC char nbuf[MAXNAMLEN + 1];
+FSTATIC char *nbufend  = &nbuf[MAXNAMLEN];
 
 
 
 
 
 
@@ -178,17 +176,17 @@ register char *pat; /* pattern to be matched in directory */
 int mkchain;  /* nonzero if results to be remembered */
 struct depblock *nextdbl;  /* final value for chain */
 {
 int mkchain;  /* nonzero if results to be remembered */
 struct depblock *nextdbl;  /* final value for chain */
 {
-FILE * dirf;
+DIR *dirf;
 register int i;
 int nread, cldir;
 char *dirname, *dirpref, *endir, *filepat, *p, temp[100];
 char fullname[100], *p1, *p2;
 struct nameblock *q;
 struct depblock *thisdbl;
 register int i;
 int nread, cldir;
 char *dirname, *dirpref, *endir, *filepat, *p, temp[100];
 char fullname[100], *p1, *p2;
 struct nameblock *q;
 struct depblock *thisdbl;
-struct opendir *od;
+struct dirhdr *od;
 struct pattern *patp;
 
 struct pattern *patp;
 
-struct direct entry[32];
+struct direct *dptr;
 
 
 thisdbl = 0;
 
 
 thisdbl = 0;
@@ -227,18 +225,19 @@ for(od = firstod; od; od = od->nxtopendir)
        if(! unequal(dirname, od->dirn) )
                {
                dirf = od->dirfc;
        if(! unequal(dirname, od->dirn) )
                {
                dirf = od->dirfc;
-               fseek(dirf, 0L, 0); /* start over at the beginning  */
+               if (dirf != NULL)
+                       rewinddir(dirf); /* start over at the beginning  */
                break;
                }
 
 if(dirf == NULL)
        {
                break;
                }
 
 if(dirf == NULL)
        {
-       dirf = fopen(dirname, "r");
+       dirf = opendir(dirname);
        if(nopdir >= MAXDIR)
                cldir = YES;
        else    {
                ++nopdir;
        if(nopdir >= MAXDIR)
                cldir = YES;
        else    {
                ++nopdir;
-               od = ALLOC(opendir);
+               od = ALLOC(dirhdr);
                od->nxtopendir = firstod;
                firstod = od;
                od->dirfc = dirf;
                od->nxtopendir = firstod;
                firstod = od;
                od->dirfc = dirf;
@@ -252,37 +251,33 @@ if(dirf == NULL)
        fatal("Cannot open");
        }
 
        fatal("Cannot open");
        }
 
-else do
+else for (dptr = readdir(dirf); dptr != NULL; dptr = readdir(dirf))
        {
        {
-       nread = fread( (char *) &entry[0], sizeof(struct direct), 32, dirf) ;
-       for(i=0; i<nread; ++i)
-               if(entry[i].d_ino!= 0)
+       p1 = dptr->d_name;
+       p2 = nbuf;
+       while( (p2<nbufend) && (*p2++ = *p1++)!='\0' )
+               /* void */;
+       if( amatch(nbuf,filepat) )
+               {
+               concat(dirpref,nbuf,fullname);
+               if( (q=srchname(fullname)) ==0)
+                       q = makename(copys(fullname));
+               if(mkchain)
                        {
                        {
-                       p1 = entry[i].d_name;
-                       p2 = n15;
-                       while( (p2<n15end) &&
-                         (*p2++ = *p1++)!='\0' );
-                       if( amatch(n15,filepat) )
-                               {
-                               concat(dirpref,n15,fullname);
-                               if( (q=srchname(fullname)) ==0)
-                                       q = makename(copys(fullname));
-                               if(mkchain)
-                                       {
-                                       thisdbl = ALLOC(depblock);
-                                       thisdbl->nxtdepblock = nextdbl;
-                                       thisdbl->depname = q;
-                                       nextdbl = thisdbl;
-                                       }
-                               }
+                       thisdbl = ALLOC(depblock);
+                       thisdbl->nxtdepblock = nextdbl;
+                       thisdbl->depname = q;
+                       nextdbl = thisdbl;
                        }
                        }
-
-       } while(nread==32);
+               }
+       }
 
 if(endir != 0)  *endir = '/';
 
 
 if(endir != 0)  *endir = '/';
 
-if(cldir)
-       fclose(dirf);
+if(cldir) {
+       closedir(dirf);
+       dirf = NULL;
+}
 return(thisdbl);
 }
 \f
 return(thisdbl);
 }
 \f
@@ -393,7 +388,7 @@ static struct nlist objentry;
 TIMETYPE lookarch(filename)
 char *filename;
 {
 TIMETYPE lookarch(filename)
 char *filename;
 {
-char *p, *q, *send, s[15];
+char *p, *q, *send, s[MAXNAMLEN + 1];
 int i, nc, nsym, objarch;
 
 for(p = filename; *p!= '(' ; ++p)
 int i, nc, nsym, objarch;
 
 for(p = filename; *p!= '(' ; ++p)
@@ -411,7 +406,7 @@ if(*p == '(')
 else
        {
        objarch = NO;
 else
        {
        objarch = NO;
-       nc = 14;
+       nc = MAXNAMLEN;
        }
 send = s + nc;
 
        }
 send = s + nc;
 
index 1f9750b..6c30a76 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)main.c      4.1 (Berkeley) 81/02/28";
+static char *sccsid = "@(#)main.c      4.2 (Berkeley) 82/04/20";
 # include "defs"
 /*
 command make to update programs.
 # include "defs"
 /*
 command make to update programs.
@@ -20,7 +20,7 @@ struct nameblock *firstname   = NULL;
 struct lineblock *sufflist     = NULL;
 struct varblock *firstvar      = NULL;
 struct pattern *firstpat       = NULL;
 struct lineblock *sufflist     = NULL;
 struct varblock *firstvar      = NULL;
 struct pattern *firstpat       = NULL;
-struct opendir *firstod                = NULL;
+struct dirhdr *firstod         = NULL;
 
 #include <signal.h>
 int sigivalue  = 0;
 
 #include <signal.h>
 int sigivalue  = 0;
@@ -325,7 +325,7 @@ int prntflag;
 struct nameblock *p;
 struct depblock *dp;
 struct varblock *vp;
 struct nameblock *p;
 struct depblock *dp;
 struct varblock *vp;
-struct opendir *od;
+struct dirhdr *od;
 struct shblock *sp;
 struct lineblock *lp;
 
 struct shblock *sp;
 struct lineblock *lp;
 
@@ -334,7 +334,7 @@ if(prntflag)
        {
        printf("Open directories:\n");
        for (od = firstod; od; od = od->nxtopendir)
        {
        printf("Open directories:\n");
        for (od = firstod; od; od = od->nxtopendir)
-               printf("\t%d: %s\n", fileno(od->dirfc), od->dirn);
+               printf("\t%d: %s\n", od->dirfc->dd_fd, od->dirn);
        }
 #endif
 
        }
 #endif