summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2000-12-11 04:00:36 +0000
committerdeischen <deischen@FreeBSD.org>2000-12-11 04:00:36 +0000
commit45428979ecbb7d5c9a2ca5dc110aee85e48d7de2 (patch)
tree4ff93d9c2aa5d2573156e1b352a4574235595006 /lib/libc/gen
parentdb0edd3c391b9475070b42d03b53f9a058882b13 (diff)
downloadFreeBSD-src-45428979ecbb7d5c9a2ca5dc110aee85e48d7de2.zip
FreeBSD-src-45428979ecbb7d5c9a2ca5dc110aee85e48d7de2.tar.gz
Move telldir position recording type definitions and prototypes
to "telldir.h" in order to prevent namespace pollution in <dirent.h> (which was including <sys/queue.h>). Add $FreeBSD$ to rewinddir.c and seekdir.c.
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/closedir.c2
-rw-r--r--lib/libc/gen/opendir.c10
-rw-r--r--lib/libc/gen/rewinddir.c5
-rw-r--r--lib/libc/gen/seekdir.c5
-rw-r--r--lib/libc/gen/telldir.c36
-rw-r--r--lib/libc/gen/telldir.h65
6 files changed, 92 insertions, 31 deletions
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index 69f1232..b1d0842 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 <stdlib.h>
#include <unistd.h>
-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 90aaec3..bd7fc82 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 <stdlib.h>
#include <unistd.h>
+#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 2076ddd..7e021b7 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 <sys/types.h>
#include <dirent.h>
-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 1934bcc..8ce57d2 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 <sys/param.h>
#include <dirent.h>
-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 fba5394..3c4b781 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 <sys/param.h>
+#include <sys/queue.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
+#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
@@ -50,33 +53,20 @@ 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
*/
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 0000000..be8a9f5
--- /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 <sys/queue.h>
+
+/*
+ * 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
OpenPOWER on IntegriCloud