CSS/Harvard 2.9BSD bug report #12
Keith Bostic
keith at seismo.CSS.GOV
Tue Oct 22 10:07:49 AEST 1985
Subject: csh
Index: bin/csh/sh.exec.c, bin/csh/sh.glob.c, bin/csh/sh.h 2.9BSD
Description:
The csh should use the new directory reading subroutines.
Fix:
The previous postings regarding reading directories applies to
csh. The following diffs can replace the old directory reading
code with the new directory reading subroutines, if you're so
inclined.
----------------------------------------------------------------------
diff sh.exec.c.wrong sh.exec.right
253,255c253,255
< struct direct dirbuf[BUFSIZ / sizeof (struct direct)];
< char d_name[MAXNAMLEN + 1];
< register int dirf, cnt;
---
> DIR *dirp;
> register struct direct *dp;
> register int cnt;
268,269c268,269
< dirf = open(*pv, 0);
< if (dirf < 0)
---
> dirp = opendir(*pv);
> if (dirp == NULL)
271,272c271,272
< if (fstat(dirf, &stb) < 0 || !isdir(stb)) {
< close(dirf);
---
> if (fstat(dirp->dd_fd, &stb) < 0 || !isdir(stb)) {
> closedir(dirp);
275,283c275,282
< 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);
< xhash[hash(d_name)] |= (1 << i);
< }
---
> while ((dp = readdir(dirp)) != NULL) {
> if (dp->d_ino == 0)
> continue;
> if (dp->d_name[0] == '.' &&
> (dp->d_name[1] == '\0' ||
> dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
> continue;
> xhash[hash(dp->d_name)] |= (1 << i);
285c284
< close(dirf);
---
> closedir(dirp);
----------------------------------------------------------------------
diff sh.glob.wrong sh.glob.right
173,175c173,174
< struct direct dirbuf[BUFSIZ / sizeof (struct direct)];
< char d_name[MAXNAMLEN+1];
< register int dirf, cnt;
---
> register struct direct *dp;
> register DIR *dirp;
177,178c176,177
< dirf = open(gpath, 0);
< if (dirf < 0) {
---
> dirp = opendir(gpath);
> if (dirp == NULL) {
181c180
< goto patherr;
---
> goto patherr2;
183,184c182,183
< if (fstat(dirf, &stb) < 0)
< goto patherr;
---
> if (fstat(dirp->dd_fd, &stb) < 0)
> goto patherr1;
187c186
< goto patherr;
---
> goto patherr1;
189,199c188,193
< 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++;
202c196
< close(dirf);
---
> closedir(dirp);
205c199,201
< patherr:
---
> patherr1:
> closedir(dirp);
> patherr2:
207,217d202
< }
<
< copdent(to, from)
< register char *to, *from;
< {
< register int cnt = MAXNAMLEN;
<
< do
< *to++ = *from++;
< while (--cnt);
< *to = 0;
----------------------------------------------------------------------
diff sh.h.wrong sh.h.right
19d20
< #define KERNEL
20d22
< #undef KERNEL
More information about the Comp.bugs.2bsd
mailing list