xref: /freebsd/lib/libc/gen/telldir.h (revision 8a16b7a18f5d0b031f09832fd7752fba717e2a97)
1*8a16b7a1SPedro F. Giffuni /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
410d1cba0SDaniel Eischen  * Copyright (c) 1983, 1993
510d1cba0SDaniel Eischen  *	The Regents of the University of California.  All rights reserved.
610d1cba0SDaniel Eischen  *
710d1cba0SDaniel Eischen  * Copyright (c) 2000
810d1cba0SDaniel Eischen  * 	Daniel Eischen.  All rights reserved.
910d1cba0SDaniel Eischen  *
1010d1cba0SDaniel Eischen  * Redistribution and use in source and binary forms, with or without
1110d1cba0SDaniel Eischen  * modification, are permitted provided that the following conditions
1210d1cba0SDaniel Eischen  * are met:
1310d1cba0SDaniel Eischen  * 1. Redistributions of source code must retain the above copyright
1410d1cba0SDaniel Eischen  *    notice, this list of conditions and the following disclaimer.
1510d1cba0SDaniel Eischen  * 2. Redistributions in binary form must reproduce the above copyright
1610d1cba0SDaniel Eischen  *    notice, this list of conditions and the following disclaimer in the
1710d1cba0SDaniel Eischen  *    documentation and/or other materials provided with the distribution.
1810d1cba0SDaniel Eischen  * 3. Neither the name of the University nor the names of its contributors
1910d1cba0SDaniel Eischen  *    may be used to endorse or promote products derived from this software
2010d1cba0SDaniel Eischen  *    without specific prior written permission.
2110d1cba0SDaniel Eischen  *
2210d1cba0SDaniel Eischen  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2310d1cba0SDaniel Eischen  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2410d1cba0SDaniel Eischen  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2510d1cba0SDaniel Eischen  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2610d1cba0SDaniel Eischen  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2710d1cba0SDaniel Eischen  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2810d1cba0SDaniel Eischen  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2910d1cba0SDaniel Eischen  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3010d1cba0SDaniel Eischen  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3110d1cba0SDaniel Eischen  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3210d1cba0SDaniel Eischen  * SUCH DAMAGE.
3310d1cba0SDaniel Eischen  *
3410d1cba0SDaniel Eischen  * $FreeBSD$
3510d1cba0SDaniel Eischen  */
3610d1cba0SDaniel Eischen 
3710d1cba0SDaniel Eischen #ifndef _TELLDIR_H_
3810d1cba0SDaniel Eischen #define	_TELLDIR_H_
3910d1cba0SDaniel Eischen 
4010d1cba0SDaniel Eischen #include <sys/queue.h>
419f72c032SJohn Baldwin #include <stdbool.h>
4210d1cba0SDaniel Eischen 
4310d1cba0SDaniel Eischen /*
4410d1cba0SDaniel Eischen  * One of these structures is malloced to describe the current directory
4510d1cba0SDaniel Eischen  * position each time telldir is called. It records the current magic
4610d1cba0SDaniel Eischen  * cookie returned by getdirentries and the offset within the buffer
4710d1cba0SDaniel Eischen  * associated with that return value.
4810d1cba0SDaniel Eischen  */
4910d1cba0SDaniel Eischen struct ddloc {
5010d1cba0SDaniel Eischen 	LIST_ENTRY(ddloc) loc_lqe; /* entry in list */
5110d1cba0SDaniel Eischen 	long	loc_index;	/* key associated with structure */
5269921123SKonstantin Belousov 	off_t	loc_seek;	/* magic cookie returned by getdirentries */
5310d1cba0SDaniel Eischen 	long	loc_loc;	/* offset of entry in buffer */
5410d1cba0SDaniel Eischen };
5510d1cba0SDaniel Eischen 
5610d1cba0SDaniel Eischen /*
5710d1cba0SDaniel Eischen  * One of these structures is malloced for each DIR to record telldir
5810d1cba0SDaniel Eischen  * positions.
5910d1cba0SDaniel Eischen  */
6010d1cba0SDaniel Eischen struct _telldir {
6110d1cba0SDaniel Eischen 	LIST_HEAD(, ddloc) td_locq; /* list of locations */
6210d1cba0SDaniel Eischen 	long	td_loccnt;	/* index of entry for sequential readdir's */
6310d1cba0SDaniel Eischen };
6410d1cba0SDaniel Eischen 
659f72c032SJohn Baldwin bool		_filldir(DIR *, bool);
6690c68c17SKonstantin Belousov struct dirent	*_readdir_unlocked(DIR *, int);
67d201fe46SDaniel Eischen void 		_reclaim_telldir(DIR *);
68d201fe46SDaniel Eischen void 		_seekdir(DIR *, long);
69af069b06SJulian Elischer void		_fixtelldir(DIR *dirp, long oldseek, long oldloc);
7010d1cba0SDaniel Eischen 
7169921123SKonstantin Belousov #define	RDU_SKIP	0x0001
7269921123SKonstantin Belousov #define	RDU_SHORT	0x0002
7369921123SKonstantin Belousov 
7410d1cba0SDaniel Eischen #endif
75