*** empty log message ***
This commit is contained in:
parent
5817719a7c
commit
9cab0b0105
5 changed files with 33 additions and 20 deletions
|
@ -1,8 +1,9 @@
|
||||||
#ifdef BSD4_2
|
#ifdef BSD4_2
|
||||||
#include "/usr/include/sys/dir.h"
|
#define MAXNAMLEN 255
|
||||||
#else
|
#else
|
||||||
#define DIRBLKSIZ 512
|
|
||||||
#define MAXNAMLEN 14
|
#define MAXNAMLEN 14
|
||||||
|
#endif
|
||||||
|
#define DIRBLKSIZ 512
|
||||||
#undef DIRSIZ
|
#undef DIRSIZ
|
||||||
#define DIRSIZ(dp) \
|
#define DIRSIZ(dp) \
|
||||||
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3)&~3))
|
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3)&~3))
|
||||||
|
@ -17,7 +18,8 @@ struct _dirdesc {
|
||||||
int dd_fd;
|
int dd_fd;
|
||||||
long dd_loc;
|
long dd_loc;
|
||||||
long dd_size;
|
long dd_size;
|
||||||
char dd_buf[DIRBLKSIZ];
|
char *dd_buf;
|
||||||
|
int dd_bsize;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _dirdesc DIR;
|
typedef struct _dirdesc DIR;
|
||||||
|
@ -25,10 +27,9 @@ typedef struct _dirdesc DIR;
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
extern DIR *opendir();
|
extern DIR *opendir();
|
||||||
extern struct direct *readdir();
|
extern struct direct *readdir();
|
||||||
extern long telldir();
|
extern long telldir();
|
||||||
extern seekdir();
|
extern seekdir();
|
||||||
#define rewinddir(dirp) seekdir((dirp), 0L)
|
#define rewinddir(dirp) seekdir((dirp), 0L)
|
||||||
extern closedir();
|
extern closedir();
|
||||||
#endif
|
|
||||||
|
|
|
@ -10,5 +10,6 @@ register DIR *dirp;
|
||||||
close(dirp->dd_fd);
|
close(dirp->dd_fd);
|
||||||
dirp->dd_fd = -1;
|
dirp->dd_fd = -1;
|
||||||
dirp->dd_loc = 0;
|
dirp->dd_loc = 0;
|
||||||
free(dirp);
|
free(dirp->dd_buf);
|
||||||
|
free((char *)dirp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,21 @@ char *name;
|
||||||
close (fd);
|
close (fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if ((int) stbuf.st_size == stbuf.st_size &&
|
||||||
|
(dirp->dd_buf = malloc((unsigned) stbuf.st_size))) {
|
||||||
|
dirp->dd_bsize = stbuf.st_size;
|
||||||
|
}
|
||||||
|
else if (dirp->dd_buf = malloc(8*DIRBLKSIZ)) {
|
||||||
|
dirp->dd_bsize = 8 * DIRBLKSIZ;
|
||||||
|
}
|
||||||
|
else if (dirp->dd_buf = malloc(DIRBLKSIZ)) {
|
||||||
|
dirp->dd_bsize = DIRBLKSIZ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close(fd);
|
||||||
|
free((char *) dirp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
dirp->dd_fd = fd;
|
dirp->dd_fd = fd;
|
||||||
dirp->dd_loc = 0;
|
dirp->dd_loc = 0;
|
||||||
return dirp;
|
return dirp;
|
||||||
|
|
|
@ -27,7 +27,7 @@ register DIR *dirp;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (dirp->dd_loc == 0) {
|
if (dirp->dd_loc == 0) {
|
||||||
dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
|
dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
|
||||||
DIRBLKSIZ);
|
dirp->dd_bsize);
|
||||||
if (dirp->dd_size <= 0) {
|
if (dirp->dd_size <= 0) {
|
||||||
dirp->dd_size = 0;
|
dirp->dd_size = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -16,22 +16,18 @@ long loc;
|
||||||
curloc = telldir(dirp);
|
curloc = telldir(dirp);
|
||||||
if (loc == curloc)
|
if (loc == curloc)
|
||||||
return;
|
return;
|
||||||
base = loc & ~(DIRBLKSIZ - 1);
|
offset = loc % dirp->dd_bsize;
|
||||||
offset = loc & (DIRBLKSIZ - 1);
|
base = loc - offset;
|
||||||
if (dirp->dd_loc != 0 && offset != 0 &&
|
if (dirp->dd_loc != 0 && offset != 0 &&
|
||||||
(curloc & ~(DIRBLKSIZ-1)) == base) {
|
(curloc - (curloc % dirp->dd_bsize)) == base) {
|
||||||
dirp->dd_loc = offset;
|
dirp->dd_loc = offset;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(void) lseek(dirp->dd_fd, base, 0);
|
(void) lseek(dirp->dd_fd, base, 0);
|
||||||
dirp->dd_loc = 0;
|
dirp->dd_loc = 0;
|
||||||
dirp->dd_size = 0;
|
dirp->dd_size = 0;
|
||||||
if (offset == 0)
|
while (dirp->dd_loc < offset) {
|
||||||
(void) readdir(dirp);
|
if (readdir(dirp) == (struct direct *) 0)
|
||||||
else {
|
return;
|
||||||
while (dirp->dd_loc < offset) {
|
|
||||||
if (readdir(dirp) == (struct direct *) 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue