Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / miscellany / libndir / readdir.c
1 static char sccsid[] = "@(#)readdir.c   4.1     (Berkeley)      83/03/21";
2
3 #include <sys/types.h>
4 #include <dir.h>
5
6 /*
7  * read an old stlye directory entry and present it as a new one
8  */
9 #define ODIRSIZ 14
10
11 struct  olddirect {
12         ino_t   od_ino;
13         char    od_name[ODIRSIZ];
14 };
15
16 /*
17  * get next entry in a directory.
18  */
19 struct direct *
20 readdir(dirp)
21         register DIR *dirp;
22 {
23         register struct olddirect *dp;
24         static struct direct dir;
25
26         for (;;) {
27                 if (dirp->dd_loc == 0) {
28                         dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
29                             DIRBLKSIZ);
30                         if (dirp->dd_size <= 0)
31                                 return NULL;
32                 }
33                 if (dirp->dd_loc >= dirp->dd_size) {
34                         dirp->dd_loc = 0;
35                         continue;
36                 }
37                 dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
38                 dirp->dd_loc += sizeof(struct olddirect);
39                 if (dp->od_ino == 0)
40                         continue;
41                 dir.d_ino = dp->od_ino;
42                 strncpy(dir.d_name, dp->od_name, ODIRSIZ);
43                 dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
44                 dir.d_namlen = strlen(dir.d_name);
45                 dir.d_reclen = DIRBLKSIZ;
46                 return (&dir);
47         }
48 }