diff options
Diffstat (limited to 'lib/libc/gen/telldir.c')
-rw-r--r-- | lib/libc/gen/telldir.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index 979fee4..ab23d9d 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -49,7 +49,7 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93"; /* * One of these structures is malloced to describe the current directory - * position each time telldir is called. It records the current magic + * position each time telldir is called. It records the current magic * cookie returned by getdirentries and the offset within the buffer * associated with that return value. */ @@ -58,6 +58,7 @@ struct ddloc { long loc_index; /* key associated with structure */ long loc_seek; /* magic cookie returned by getdirentries */ long loc_loc; /* offset of entry in buffer */ + const DIR* loc_dirp; /* directory which used this entry */ }; #define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */ @@ -82,6 +83,7 @@ telldir(dirp) lp->loc_index = index; lp->loc_seek = dirp->dd_seek; lp->loc_loc = dirp->dd_loc; + lp->loc_dirp = dirp; lp->loc_next = dd_hash[LOCHASH(index)]; dd_hash[LOCHASH(index)] = lp; return (index); @@ -126,3 +128,30 @@ found: free((caddr_t)lp); #endif } + +/* + * Reclaim memory for telldir cookies which weren't used. + */ +void +_reclaim_telldir(dirp) + register const DIR *dirp; +{ + register struct ddloc *lp; + register struct ddloc **prevlp; + int i; + + for (i = 0; i < NDIRHASH; i++) { + prevlp = &dd_hash[i]; + lp = *prevlp; + while (lp != NULL) { + if (lp->loc_dirp == dirp) { + *prevlp = lp->loc_next; + free((caddr_t)lp); + lp = *prevlp; + continue; + } + prevlp = &lp->loc_next; + lp = lp->loc_next; + } + } +} |