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:
parent
3d48aa2a7c
commit
10d1cba0bf
@ -42,7 +42,6 @@
|
|||||||
* the getdirentries(2) system call.
|
* the getdirentries(2) system call.
|
||||||
*/
|
*/
|
||||||
#include <sys/dirent.h>
|
#include <sys/dirent.h>
|
||||||
#include <sys/queue.h>
|
|
||||||
|
|
||||||
#ifdef _POSIX_SOURCE
|
#ifdef _POSIX_SOURCE
|
||||||
typedef void * DIR;
|
typedef void * DIR;
|
||||||
@ -53,7 +52,7 @@ typedef void * DIR;
|
|||||||
/* definitions for library routines operating on directories. */
|
/* definitions for library routines operating on directories. */
|
||||||
#define DIRBLKSIZ 1024
|
#define DIRBLKSIZ 1024
|
||||||
|
|
||||||
struct _ddloc;
|
struct _telldir; /* see telldir.h */
|
||||||
|
|
||||||
/* structure describing an open directory. */
|
/* structure describing an open directory. */
|
||||||
typedef struct _dirdesc {
|
typedef struct _dirdesc {
|
||||||
@ -65,8 +64,7 @@ typedef struct _dirdesc {
|
|||||||
long dd_seek; /* magic cookie returned by getdirentries */
|
long dd_seek; /* magic cookie returned by getdirentries */
|
||||||
long dd_rewind; /* magic cookie for rewinding */
|
long dd_rewind; /* magic cookie for rewinding */
|
||||||
int dd_flags; /* flags for readdir */
|
int dd_flags; /* flags for readdir */
|
||||||
long dd_loccnt; /* Index of entry for sequential readdir's */
|
struct _telldir *dd_td; /* telldir position recording */
|
||||||
LIST_HEAD(, _ddloc) dd_locq; /* telldir position recording */
|
|
||||||
} DIR;
|
} DIR;
|
||||||
|
|
||||||
#define dirfd(dirp) ((dirp)->dd_fd)
|
#define dirfd(dirp) ((dirp)->dd_fd)
|
||||||
|
@ -42,7 +42,7 @@ static char sccsid[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93";
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern void _reclaim_telldir __P((DIR *));
|
#include "telldir.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* close a directory.
|
* close a directory.
|
||||||
|
@ -47,6 +47,8 @@ static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95";
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "telldir.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open a directory.
|
* Open a directory.
|
||||||
*/
|
*/
|
||||||
@ -90,9 +92,13 @@ __opendir2(name, flags)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
|
if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 ||
|
||||||
(dirp = malloc(sizeof(DIR))) == NULL)
|
(dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
|
||||||
goto fail;
|
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.
|
* Use the system page size if that is a multiple of DIRBLKSIZ.
|
||||||
* Hopefully this can be a big win someday by allowing page
|
* Hopefully this can be a big win someday by allowing page
|
||||||
@ -259,8 +265,6 @@ __opendir2(name, flags)
|
|||||||
dirp->dd_loc = 0;
|
dirp->dd_loc = 0;
|
||||||
dirp->dd_fd = fd;
|
dirp->dd_fd = fd;
|
||||||
dirp->dd_flags = flags;
|
dirp->dd_flags = flags;
|
||||||
dirp->dd_loccnt = 0;
|
|
||||||
LIST_INIT(&dirp->dd_locq);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up seek point for rewinddir.
|
* Set up seek point for rewinddir.
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#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 <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
extern void _seekdir __P(( DIR *, long ));
|
#include "telldir.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
rewinddir(dirp)
|
rewinddir(dirp)
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
{
|
{
|
||||||
|
|
||||||
_seekdir(dirp, dirp->dd_rewind);
|
_seekdir(dirp, dirp->dd_rewind);
|
||||||
dirp->dd_rewind = telldir(dirp);
|
dirp->dd_rewind = telldir(dirp);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#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 <sys/param.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
extern void _seekdir __P(( DIR *, long ));
|
#include "telldir.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Seek to an entry in a directory.
|
* Seek to an entry in a directory.
|
||||||
@ -49,6 +51,5 @@ seekdir(dirp, loc)
|
|||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
long loc;
|
long loc;
|
||||||
{
|
{
|
||||||
|
|
||||||
_seekdir(dirp, loc);
|
_seekdir(dirp, loc);
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,13 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93";
|
|||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "telldir.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The option SINGLEUSE may be defined to say that a telldir
|
* The option SINGLEUSE may be defined to say that a telldir
|
||||||
* cookie may be used only once before it is freed. This option
|
* 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
|
#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
|
* return a pointer into a directory
|
||||||
*/
|
*/
|
||||||
@ -69,14 +59,14 @@ long
|
|||||||
telldir(dirp)
|
telldir(dirp)
|
||||||
DIR *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);
|
return (-1);
|
||||||
lp->loc_index = dirp->dd_loccnt++;
|
lp->loc_index = dirp->dd_td->td_loccnt++;
|
||||||
lp->loc_seek = dirp->dd_seek;
|
lp->loc_seek = dirp->dd_seek;
|
||||||
lp->loc_loc = dirp->dd_loc;
|
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);
|
return (lp->loc_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,10 +79,10 @@ _seekdir(dirp, loc)
|
|||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
long loc;
|
long loc;
|
||||||
{
|
{
|
||||||
struct _ddloc *lp;
|
struct ddloc *lp;
|
||||||
struct dirent *dp;
|
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)
|
if (lp->loc_index == loc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -122,14 +112,14 @@ void
|
|||||||
_reclaim_telldir(dirp)
|
_reclaim_telldir(dirp)
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
{
|
{
|
||||||
struct _ddloc *lp;
|
struct ddloc *lp;
|
||||||
struct _ddloc *templp;
|
struct ddloc *templp;
|
||||||
|
|
||||||
lp = LIST_FIRST(&dirp->dd_locq);
|
lp = LIST_FIRST(&dirp->dd_td->td_locq);
|
||||||
while (lp != NULL) {
|
while (lp != NULL) {
|
||||||
templp = lp;
|
templp = lp;
|
||||||
lp = LIST_NEXT(lp, loc_lqe);
|
lp = LIST_NEXT(lp, loc_lqe);
|
||||||
free(templp);
|
free(templp);
|
||||||
}
|
}
|
||||||
LIST_INIT(&dirp->dd_locq);
|
LIST_INIT(&dirp->dd_td->td_locq);
|
||||||
}
|
}
|
||||||
|
65
lib/libc/gen/telldir.h
Normal file
65
lib/libc/gen/telldir.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user