xref: /openbsd/include/glob.h (revision b59f966d)
1*b59f966dSmillert /*	$OpenBSD: glob.h,v 1.14 2019/02/04 16:45:40 millert Exp $	*/
2df930be7Sderaadt /*	$NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1989, 1993
6df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * This code is derived from software contributed to Berkeley by
9df930be7Sderaadt  * Guido van Rossum.
10df930be7Sderaadt  *
11df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt  * modification, are permitted provided that the following conditions
13df930be7Sderaadt  * are met:
14df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
19e33d3bd3Smillert  * 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
21df930be7Sderaadt  *    without specific prior written permission.
22df930be7Sderaadt  *
23df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt  * SUCH DAMAGE.
34df930be7Sderaadt  *
35df930be7Sderaadt  *	@(#)glob.h	8.1 (Berkeley) 6/2/93
36df930be7Sderaadt  */
37df930be7Sderaadt 
38df930be7Sderaadt #ifndef _GLOB_H_
39df930be7Sderaadt #define	_GLOB_H_
40df930be7Sderaadt 
41baa4cfeaSdjm #include <sys/stat.h>
42*b59f966dSmillert #include <machine/_types.h>
43*b59f966dSmillert 
44*b59f966dSmillert #ifndef	_SIZE_T_DEFINED_
45*b59f966dSmillert #define	_SIZE_T_DEFINED_
46*b59f966dSmillert typedef	__size_t	size_t;
47*b59f966dSmillert #endif
48df930be7Sderaadt 
49df930be7Sderaadt struct stat;
50df930be7Sderaadt typedef struct {
51*b59f966dSmillert 	size_t gl_pathc;	/* Count of total paths so far. */
52*b59f966dSmillert 	size_t gl_matchc;	/* Count of paths matching pattern. */
53*b59f966dSmillert 	size_t gl_offs;		/* Reserved at beginning of gl_pathv. */
54df930be7Sderaadt 	int gl_flags;		/* Copy of flags parameter to glob. */
55df930be7Sderaadt 	char **gl_pathv;	/* List of paths matching pattern. */
56baa4cfeaSdjm 	struct stat **gl_statv;	/* Stat entries corresponding to gl_pathv */
57df930be7Sderaadt 				/* Copy of errfunc parameter to glob. */
58c72b5b24Smillert 	int (*gl_errfunc)(const char *, int);
59df930be7Sderaadt 
60df930be7Sderaadt 	/*
61df930be7Sderaadt 	 * Alternate filesystem access methods for glob; replacement
62df930be7Sderaadt 	 * versions of closedir(3), readdir(3), opendir(3), stat(2)
63df930be7Sderaadt 	 * and lstat(2).
64df930be7Sderaadt 	 */
65c72b5b24Smillert 	void (*gl_closedir)(void *);
66c72b5b24Smillert 	struct dirent *(*gl_readdir)(void *);
67c72b5b24Smillert 	void *(*gl_opendir)(const char *);
68c72b5b24Smillert 	int (*gl_lstat)(const char *, struct stat *);
69c72b5b24Smillert 	int (*gl_stat)(const char *, struct stat *);
70df930be7Sderaadt } glob_t;
71df930be7Sderaadt 
72df930be7Sderaadt #define	GLOB_APPEND	0x0001	/* Append to output from previous call. */
73df930be7Sderaadt #define	GLOB_DOOFFS	0x0002	/* Use gl_offs. */
74df930be7Sderaadt #define	GLOB_ERR	0x0004	/* Return on error. */
75df930be7Sderaadt #define	GLOB_MARK	0x0008	/* Append / to matching directories. */
76df930be7Sderaadt #define	GLOB_NOCHECK	0x0010	/* Return pattern itself if nothing matches. */
77df930be7Sderaadt #define	GLOB_NOSORT	0x0020	/* Don't sort. */
780dc20d98Smillert #define	GLOB_NOESCAPE	0x1000	/* Disable backslash escaping. */
79df930be7Sderaadt 
8052a0e603Smillert #define	GLOB_NOSPACE	(-1)	/* Malloc call failed. */
8152a0e603Smillert #define	GLOB_ABORTED	(-2)	/* Unignored error. */
8252a0e603Smillert #define	GLOB_NOMATCH	(-3)	/* No match and GLOB_NOCHECK not set. */
8352a0e603Smillert #define	GLOB_NOSYS	(-4)	/* Function not supported. */
8452a0e603Smillert 
8552a0e603Smillert #if __BSD_VISIBLE
86df930be7Sderaadt #define	GLOB_ALTDIRFUNC	0x0040	/* Use alternately specified directory funcs. */
87df930be7Sderaadt #define	GLOB_BRACE	0x0080	/* Expand braces ala csh. */
88df930be7Sderaadt #define	GLOB_MAGCHAR	0x0100	/* Pattern had globbing characters. */
89df930be7Sderaadt #define	GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
90df930be7Sderaadt #define	GLOB_QUOTE	0x0400	/* Quote special chars with \. */
91df930be7Sderaadt #define	GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
9298e12176Sderaadt #define GLOB_LIMIT	0x2000	/* Limit pattern match output to ARG_MAX */
93baa4cfeaSdjm #define	GLOB_KEEPSTAT	0x4000	/* Retain stat data for paths in gl_statv. */
9452a0e603Smillert #define GLOB_ABEND	GLOB_ABORTED /* backward compatibility */
95df930be7Sderaadt #endif
96df930be7Sderaadt 
97df930be7Sderaadt __BEGIN_DECLS
982c79e7ccSguenther int	glob(const char *__restrict, int, int (*)(const char *, int),
992c79e7ccSguenther 	    glob_t *__restrict);
100c72b5b24Smillert void	globfree(glob_t *);
101df930be7Sderaadt __END_DECLS
102df930be7Sderaadt 
103df930be7Sderaadt #endif /* !_GLOB_H_ */
104