*** empty log message ***
authorceriel <none@none>
Tue, 24 Feb 1987 13:10:59 +0000 (13:10 +0000)
committerceriel <none@none>
Tue, 24 Feb 1987 13:10:59 +0000 (13:10 +0000)
include/_tail_cc/sys/dir.h
lang/cem/libcc/gen/closedir.c
lang/cem/libcc/gen/opendir.c
lang/cem/libcc/gen/readdir.c
lang/cem/libcc/gen/seekdir.c

index 256222e..ef327d4 100644 (file)
@@ -1,8 +1,9 @@
 #ifdef BSD4_2
-#include "/usr/include/sys/dir.h"
+#define MAXNAMLEN 255
 #else
-#define DIRBLKSIZ 512
 #define MAXNAMLEN 14
+#endif
+#define DIRBLKSIZ 512
 #undef DIRSIZ
 #define DIRSIZ(dp) \
        ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3)&~3))
@@ -17,7 +18,8 @@ struct _dirdesc {
        int     dd_fd;
        long    dd_loc;
        long    dd_size;
-       char    dd_buf[DIRBLKSIZ];
+       char    *dd_buf;
+       int     dd_bsize;
 };
 
 typedef struct _dirdesc DIR;
@@ -25,10 +27,9 @@ typedef struct _dirdesc DIR;
 #ifndef NULL
 #define NULL 0
 #endif
-extern DIR     *opendir();
+extern DIR *opendir();
 extern struct direct *readdir();
-extern long    telldir();
-extern         seekdir();
+extern long telldir();
+extern seekdir();
 #define rewinddir(dirp) seekdir((dirp), 0L)
-extern         closedir();
-#endif
+extern closedir();
index 0fc2f75..d7f71c6 100644 (file)
@@ -10,5 +10,6 @@ register DIR *dirp;
        close(dirp->dd_fd);
        dirp->dd_fd = -1;
        dirp->dd_loc = 0;
-       free(dirp);
+       free(dirp->dd_buf);
+       free((char *)dirp);
 }
index 35e5185..f017428 100644 (file)
@@ -21,6 +21,21 @@ char *name;
                close (fd);
                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_loc = 0;
        return dirp;
index 6679dd5..fb8ea60 100644 (file)
@@ -27,7 +27,7 @@ register DIR *dirp;
        for (;;) {
                if (dirp->dd_loc == 0) {
                        dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
-                                            DIRBLKSIZ);
+                                            dirp->dd_bsize);
                        if (dirp->dd_size <= 0) {
                                dirp->dd_size = 0;
                                return NULL;
index ee2e0d2..caaf9c7 100644 (file)
@@ -16,22 +16,18 @@ long loc;
        curloc = telldir(dirp);
        if (loc == curloc)
                return;
-       base = loc & ~(DIRBLKSIZ - 1);
-       offset = loc & (DIRBLKSIZ - 1);
+       offset = loc % dirp->dd_bsize;
+       base = loc - offset;
        if (dirp->dd_loc != 0 && offset != 0 &&
-           (curloc & ~(DIRBLKSIZ-1)) ==  base) {
+           (curloc - (curloc % dirp->dd_bsize)) ==  base) {
                dirp->dd_loc = offset;
                return;
        }
        (void) lseek(dirp->dd_fd, base, 0);
        dirp->dd_loc = 0;
        dirp->dd_size = 0;
-       if (offset == 0)
-               (void) readdir(dirp);
-       else {
-               while (dirp->dd_loc < offset) {
-                       if (readdir(dirp) == (struct direct *) 0)
-                               return;
-               }
+       while (dirp->dd_loc < offset) {
+               if (readdir(dirp) == (struct direct *) 0)
+                       return;
        }
 }