From 10d1cba0bf09c9bdbdc2ac7ff62b9516de75db4c Mon Sep 17 00:00:00 2001 From: Daniel Eischen Date: Mon, 11 Dec 2000 04:00:36 +0000 Subject: [PATCH] Move telldir position recording type definitions and prototypes to "telldir.h" in order to prevent namespace pollution in (which was including ). Add $FreeBSD$ to rewinddir.c and seekdir.c. --- include/dirent.h | 6 ++-- lib/libc/gen/closedir.c | 2 +- lib/libc/gen/opendir.c | 10 +++++-- lib/libc/gen/rewinddir.c | 5 ++-- lib/libc/gen/seekdir.c | 5 ++-- lib/libc/gen/telldir.c | 36 ++++++++-------------- lib/libc/gen/telldir.h | 65 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 94 insertions(+), 35 deletions(-) create mode 100644 lib/libc/gen/telldir.h diff --git a/include/dirent.h b/include/dirent.h index d24c1467bed6..2028d7b34649 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -42,7 +42,6 @@ * the getdirentries(2) system call. */ #include -#include #ifdef _POSIX_SOURCE typedef void * DIR; @@ -53,7 +52,7 @@ typedef void * DIR; /* definitions for library routines operating on directories. */ #define DIRBLKSIZ 1024 -struct _ddloc; +struct _telldir; /* see telldir.h */ /* structure describing an open directory. */ typedef struct _dirdesc { @@ -65,8 +64,7 @@ typedef struct _dirdesc { long dd_seek; /* magic cookie returned by getdirentries */ long dd_rewind; /* magic cookie for rewinding */ int dd_flags; /* flags for readdir */ - long dd_loccnt; /* Index of entry for sequential readdir's */ - LIST_HEAD(, _ddloc) dd_locq; /* telldir position recording */ + struct _telldir *dd_td; /* telldir position recording */ } DIR; #define dirfd(dirp) ((dirp)->dd_fd) diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index 69f1232815c7..b1d0842fe2a1 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -42,7 +42,7 @@ static char sccsid[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93"; #include #include -extern void _reclaim_telldir __P((DIR *)); +#include "telldir.h" /* * close a directory. diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 90aaec32e196..bd7fc82ab0b7 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -47,6 +47,8 @@ static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; #include #include +#include "telldir.h" + /* * Open a directory. */ @@ -90,9 +92,13 @@ __opendir2(name, flags) goto fail; } if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || - (dirp = malloc(sizeof(DIR))) == NULL) + (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL) goto fail; + dirp->dd_td = (void *)dirp + sizeof(DIR); + LIST_INIT(&dirp->dd_td->td_locq); + dirp->dd_td->td_loccnt = 0; + /* * Use the system page size if that is a multiple of DIRBLKSIZ. * Hopefully this can be a big win someday by allowing page @@ -259,8 +265,6 @@ __opendir2(name, flags) dirp->dd_loc = 0; dirp->dd_fd = fd; dirp->dd_flags = flags; - dirp->dd_loccnt = 0; - LIST_INIT(&dirp->dd_locq); /* * Set up seek point for rewinddir. diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c index 2076dddea4be..7e021b7f65ee 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/rewinddir.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -38,13 +40,12 @@ static char sccsid[] = "@(#)rewinddir.c 8.1 (Berkeley) 6/8/93"; #include #include -extern void _seekdir __P(( DIR *, long )); +#include "telldir.h" void rewinddir(dirp) DIR *dirp; { - _seekdir(dirp, dirp->dd_rewind); dirp->dd_rewind = telldir(dirp); } diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c index 1934bcc38a8e..8ce57d2bf32d 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/seekdir.c @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -38,7 +40,7 @@ static char sccsid[] = "@(#)seekdir.c 8.1 (Berkeley) 6/4/93"; #include #include -extern void _seekdir __P(( DIR *, long )); +#include "telldir.h" /* * Seek to an entry in a directory. @@ -49,6 +51,5 @@ seekdir(dirp, loc) DIR *dirp; long loc; { - _seekdir(dirp, loc); } diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index fba53941dcbb..3c4b781e2606 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -38,10 +38,13 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include +#include #include #include #include +#include "telldir.h" + /* * The option SINGLEUSE may be defined to say that a telldir * cookie may be used only once before it is freed. This option @@ -49,19 +52,6 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93"; */ #define SINGLEUSE -/* - * One of these structures is malloced to describe the current directory - * 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. - */ -struct _ddloc { - LIST_ENTRY(_ddloc) loc_lqe; /* entry in list */ - long loc_index; /* key associated with structure */ - long loc_seek; /* magic cookie returned by getdirentries */ - long loc_loc; /* offset of entry in buffer */ -}; - /* * return a pointer into a directory */ @@ -69,14 +59,14 @@ long telldir(dirp) DIR *dirp; { - struct _ddloc *lp; + struct ddloc *lp; - if ((lp = (struct _ddloc *)malloc(sizeof(struct _ddloc))) == NULL) + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) return (-1); - lp->loc_index = dirp->dd_loccnt++; + lp->loc_index = dirp->dd_td->td_loccnt++; lp->loc_seek = dirp->dd_seek; lp->loc_loc = dirp->dd_loc; - LIST_INSERT_HEAD(&dirp->dd_locq, lp, loc_lqe); + LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe); return (lp->loc_index); } @@ -89,10 +79,10 @@ _seekdir(dirp, loc) DIR *dirp; long loc; { - struct _ddloc *lp; + struct ddloc *lp; struct dirent *dp; - LIST_FOREACH(lp, &dirp->dd_locq, loc_lqe) { + LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) { if (lp->loc_index == loc) break; } @@ -122,14 +112,14 @@ void _reclaim_telldir(dirp) DIR *dirp; { - struct _ddloc *lp; - struct _ddloc *templp; + struct ddloc *lp; + struct ddloc *templp; - lp = LIST_FIRST(&dirp->dd_locq); + lp = LIST_FIRST(&dirp->dd_td->td_locq); while (lp != NULL) { templp = lp; lp = LIST_NEXT(lp, loc_lqe); free(templp); } - LIST_INIT(&dirp->dd_locq); + LIST_INIT(&dirp->dd_td->td_locq); } diff --git a/lib/libc/gen/telldir.h b/lib/libc/gen/telldir.h new file mode 100644 index 000000000000..be8a9f5417c2 --- /dev/null +++ b/lib/libc/gen/telldir.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 2000 + * Daniel Eischen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _TELLDIR_H_ +#define _TELLDIR_H_ + +#include + +/* + * One of these structures is malloced to describe the current directory + * 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. + */ +struct ddloc { + LIST_ENTRY(ddloc) loc_lqe; /* entry in list */ + long loc_index; /* key associated with structure */ + long loc_seek; /* magic cookie returned by getdirentries */ + long loc_loc; /* offset of entry in buffer */ +}; + +/* + * One of these structures is malloced for each DIR to record telldir + * positions. + */ +struct _telldir { + LIST_HEAD(, ddloc) td_locq; /* list of locations */ + long td_loccnt; /* index of entry for sequential readdir's */ +}; + +void _reclaim_telldir __P((DIR *)); +void _seekdir __P((DIR *, long)); + +#endif