minor adaption, to close filedescriptor immediatelym if possible

This commit is contained in:
ceriel 1987-03-27 15:11:06 +00:00
parent 19d29e4018
commit e3043b7dcb
5 changed files with 18 additions and 10 deletions

View file

@ -7,9 +7,9 @@
closedir(dirp)
register DIR *dirp;
{
close(dirp->dd_fd);
if (dirp->dd_fd >= 0) close(dirp->dd_fd);
dirp->dd_fd = -1;
dirp->dd_loc = 0;
dirp->dd_loc = -1;
free(dirp->dd_buf);
free((char *)dirp);
}

View file

@ -21,9 +21,14 @@ char *name;
close (fd);
return NULL;
}
if ((int) stbuf.st_size == stbuf.st_size &&
if ((unsigned) stbuf.st_size == stbuf.st_size &&
(dirp->dd_buf = malloc((unsigned) stbuf.st_size))) {
dirp->dd_bsize = stbuf.st_size;
read(fd, dirp->dd_buf, dirp->dd_bsize);
close(fd);
dirp->dd_fd = -2;
dirp->dd_loc = 0;
return dirp;
}
else if (dirp->dd_buf = malloc(8*DIRBLKSIZ)) {
dirp->dd_bsize = 8 * DIRBLKSIZ;
@ -37,6 +42,6 @@ char *name;
return NULL;
}
dirp->dd_fd = fd;
dirp->dd_loc = 0;
dirp->dd_loc = -1;
return dirp;
}

View file

@ -25,21 +25,22 @@ register DIR *dirp;
static struct direct dir;
for (;;) {
if (dirp->dd_loc == 0) {
if (dirp->dd_loc == -1) {
dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
dirp->dd_bsize);
if (dirp->dd_size <= 0) {
dirp->dd_size = 0;
return NULL;
}
dirp->dd_loc = 0;
#ifdef __BSD4_2
if (! ((struct direct *) dirp->dd_buf)->d_ino) {
dirp->dd_loc += ((struct direct *)dirp->dd_buf)->d_reclen;
dirp->dd_loc = ((struct direct *)dirp->dd_buf)->d_reclen;
}
#endif
}
if (dirp->dd_loc >= dirp->dd_size) {
dirp->dd_loc = 0;
dirp->dd_loc = -1;
continue;
}
dp = (struct olddirect *) (dirp->dd_buf + dirp->dd_loc);

View file

@ -18,13 +18,13 @@ long loc;
return;
offset = loc % dirp->dd_bsize;
base = loc - offset;
if (dirp->dd_loc != 0 && offset != 0 &&
if (dirp->dd_loc != -1 &&
(curloc - (curloc % dirp->dd_bsize)) == base) {
dirp->dd_loc = offset;
return;
}
(void) lseek(dirp->dd_fd, base, 0);
dirp->dd_loc = 0;
dirp->dd_loc = -1;
dirp->dd_size = 0;
while (dirp->dd_loc < offset) {
if (readdir(dirp) == (struct direct *) 0)

View file

@ -9,5 +9,7 @@ DIR *dirp;
{
extern long lseek();
return (lseek(dirp->dd_fd, 0L, 1) - dirp->dd_size + dirp->dd_loc);
if (dirp->dd_fd >= 0)
return (lseek(dirp->dd_fd, 0L, 1) - dirp->dd_size + dirp->dd_loc);
return dirp->dd_loc;
}