Re: I need help

Peter K (pko@paradigm-sa.com)
Tue, 23 Jul 1996 12:12:50 +0200 (GMT+0200)


> if (fstat(dirp->dd_fd, &stb) < 0)

[snip]

Although it works, it is not very good to use DIRENT_ILLEGAL_ACCESS.

Patch glob.c in ~/src with the following patch. It moves some stuff around
and uses the "legal" typedef of DIR.

--------------------------------- snip ---------------------------------
--- glob.c.was Thu Jul 18 11:46:43 1996
+++ glob.c Tue Jul 23 12:07:36 1996
@@ -231,18 +231,24 @@

DIR *dirp;

- dirp = opendir(*gpath == '\0' ? "." : gpath);
- if (dirp == NULL) {
- if (globbed)
- return;
- goto patherr2;
+ if (*gpath == '\0') {
+ *gpath = '.';
+ *(gpath + 1) = '\0';
}
- if (fstat(dirp->dd_fd, &stb) < 0)
+
+ if (stat(gpath, &stb) < 0)
goto patherr1;
if (!isdir(stb)) {
errno = ENOTDIR;
goto patherr1;
}
+ dirp = opendir(gpath);
+ if (dirp == NULL) {
+ if (globbed)
+ return;
+ globerr = "Bad directory components";
+ return
+ }
while ((dp = readdir(dirp)) != NULL) {
if (dp->d_ino == 0)
continue;
@@ -251,13 +257,8 @@
globcnt++;
}
}
- closedir(dirp);
- return;
-
patherr1:
closedir(dirp);
-patherr2:
- globerr = "Bad directory components";
}

static int
----------------------------------- snip -----------------------------

Peter Kooiman | Fax : ++27-12-663-4191/2
Paradigm Systems Technology |
Pretoria, South Africa | UUCP : pko@silmaril.UUCP
Voice : ++27-12-672-5700/10 | DNS : pko@paradigm-sa.com