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