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.
This commit is contained in:
Daniel Eischen 2000-12-11 04:00:36 +00:00
parent 3d48aa2a7c
commit 10d1cba0bf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=69841
7 changed files with 94 additions and 35 deletions

View file

@ -42,7 +42,6 @@
* the getdirentries(2) system call.
*/
#include <sys/dirent.h>
#include <sys/queue.h>
#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)

View file

@ -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.

View file

@ -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.

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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
@ -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);
}

65
lib/libc/gen/telldir.h Normal file
View file

@ -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