update to new fs
[unix-history] / usr / src / bin / csh / glob.c
index 80a77a3..4434d0b 100644 (file)
@@ -1,5 +1,7 @@
-static char *sccsid = "@(#)glob.c 4.1 %G%";
+static char *sccsid = "@(#)glob.c 4.4 %G%";
+
 #include "sh.h"
 #include "sh.h"
+#include <dir.h>
 
 /*
  * C Shell
 
 /*
  * C Shell
@@ -75,9 +77,10 @@ collect(as)
 #ifdef GDEBUG
                printf("acollect done\n");
 #endif
 #ifdef GDEBUG
                printf("acollect done\n");
 #endif
-       } else if (noglob)
+       } else if (noglob || eq(as, "{") || eq(as, "{}")) {
                Gcat(as, "");
                Gcat(as, "");
-       else
+               sort();
+       } else
                acollect(as);
 }
 
                acollect(as);
 }
 
@@ -169,53 +172,39 @@ matchdir(pattern)
        char *pattern;
 {
        struct stat stb;
        char *pattern;
 {
        struct stat stb;
-       struct direct dirbuf[BUFSIZ / sizeof (struct direct)];
-       char d_name[DIRSIZ+1];
-       register int dirf, cnt;
+       register struct direct *dp;
+       DIR *dirp;
+       register int cnt;
 
 
-       dirf = open(gpath, 0);
-       if (dirf < 0) {
+       dirp = opendir(gpath);
+       if (dirp == NULL) {
                if (globbed)
                        return;
                if (globbed)
                        return;
-               goto patherr;
+               goto patherr2;
        }
        }
-       if (fstat(dirf, &stb) < 0)
-               goto patherr;
+       if (fstat(dirp->dd_fd, &stb) < 0)
+               goto patherr1;
        if (!isdir(stb)) {
                errno = ENOTDIR;
        if (!isdir(stb)) {
                errno = ENOTDIR;
-               goto patherr;
+               goto patherr1;
        }
        }
-       while ((cnt = read(dirf, (char *) dirbuf, sizeof dirbuf)) >= sizeof dirbuf[0]) {
-               register struct direct *ep = dirbuf;
-
-               for (cnt /= sizeof (struct direct); cnt > 0; cnt--, ep++) {
-                       if (ep->d_ino == 0)
-                               continue;
-                       copdent(d_name, ep->d_name);
-                       if (match(d_name, pattern)) {
-                               Gcat(gpath, d_name);
-                               globcnt++;
-                       }
+       while ((dp = readdir(dirp)) != NULL) {
+               if (dp->d_ino == 0)
+                       continue;
+               if (match(dp->d_name, pattern)) {
+                       Gcat(gpath, dp->d_name);
+                       globcnt++;
                }
        }
                }
        }
-       close(dirf);
+       closedir(dirp);
        return;
 
        return;
 
-patherr:
+patherr1:
+       closedir(dirp);
+patherr2:
        Perror(gpath);
 }
 
        Perror(gpath);
 }
 
-copdent(to, from)
-       register char *to, *from;
-{
-       register int cnt = DIRSIZ;
-
-       do
-               *to++ = *from++;
-       while (--cnt);
-       *to = 0;
-}
-
 execbrc(p, s)
        char *p, *s;
 {
 execbrc(p, s)
        char *p, *s;
 {