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