xref: /titanic_52/usr/src/head/glob.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25  * Copyright 1985, 1992 by Mortice Kern Systems Inc.  All rights reserved.
26  */
27 
28 /*
29  * Copyright (c) 1989, 1993
30  *	The Regents of the University of California.  All rights reserved.
31  *
32  * This code is derived from software contributed to Berkeley by
33  * Guido van Rossum.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  * 3. Neither the name of the University nor the names of its contributors
44  *    may be used to endorse or promote products derived from this software
45  *    without specific prior written permission.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57  * SUCH DAMAGE.
58  *
59  *	@(#)glob.h	8.1 (Berkeley) 6/2/93
60  */
61 
62 /*
63  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
64  * Use is subject to license terms.
65  * Copyright (c) 2013 Gary Mills
66  */
67 
68 #ifndef	_GLOB_H
69 #define	_GLOB_H
70 
71 #include <sys/feature_tests.h>
72 #include <sys/types.h>
73 #include <sys/stat.h>
74 #include <dirent.h>
75 
76 #ifdef	__cplusplus
77 extern "C" {
78 #endif
79 
80 typedef	struct	glob_t	{
81 	/*
82 	 * Members specified by POSIX
83 	 */
84 	size_t	gl_pathc;	/* Total count of paths matched by pattern */
85 	char	**gl_pathv;	/* List of matched pathnames */
86 	size_t	gl_offs;	/* # of slots reserved in gl_pathv */
87 
88 	/*
89 	 * Internal-use members:
90 	 *
91 	 * NB: The next two members are carried in both the
92 	 * libc backward compatibility wrapper functions and
93 	 * the extended functions.
94 	 */
95 	char	**gl_pathp;	/* gl_pathv + gl_offs */
96 	int	gl_pathn;	/* # of elements allocated */
97 
98 	/*
99 	 * Non-POSIX extensions
100 	 *
101 	 * NB: The following members are not carried in
102 	 * the libc backward compatibility wrapper functions.
103 	 */
104 	int	gl_matchc;	/* Count of paths matching pattern. */
105 	int	gl_flags;	/* Copy of flags parameter to glob. */
106 	struct	stat **gl_statv; /* Stat entries corresponding to gl_pathv */
107 
108 	/*
109 	 * Alternate filesystem access methods for glob; replacement
110 	 * versions of closedir(3), readdir(3), opendir(3), stat(2)
111 	 * and lstat(2).
112 	 */
113 	void (*gl_closedir)(void *);
114 	struct dirent *(*gl_readdir)(void *);
115 	void *(*gl_opendir)(const char *);
116 	int (*gl_lstat)(const char *, struct stat *);
117 	int (*gl_stat)(const char *, struct stat *);
118 }	glob_t;
119 
120 /*
121  * POSIX "flags" argument to glob function.
122  */
123 #define	GLOB_ERR	0x0001		/* Don't continue on directory error */
124 #define	GLOB_MARK	0x0002		/* Mark directories with trailing / */
125 #define	GLOB_NOSORT	0x0004		/* Don't sort pathnames */
126 #define	GLOB_NOCHECK	0x0008		/* Return unquoted arg if no match */
127 #define	GLOB_DOOFFS	0x0010		/* Ignore gl_offs unless set */
128 #define	GLOB_APPEND	0x0020		/* Append to previous glob_t */
129 #define	GLOB_NOESCAPE	0x0040		/* Backslashes do not quote M-chars */
130 
131 /*
132  * Non-POSIX "flags" argument to glob function, from OpenBSD.
133  */
134 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
135 #define	GLOB_POSIX	0x007F	/* All POSIX flags */
136 #define	GLOB_BRACE	0x0080	/* Expand braces ala csh. */
137 #define	GLOB_MAGCHAR	0x0100	/* Pattern had globbing characters. */
138 #define	GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
139 #define	GLOB_QUOTE	0x0400	/* Quote special chars with \. */
140 #define	GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
141 #define	GLOB_LIMIT	0x2000	/* Limit pattern match output to ARG_MAX */
142 #define	GLOB_KEEPSTAT	0x4000	/* Retain stat data for paths in gl_statv. */
143 #define	GLOB_ALTDIRFUNC	0x8000	/* Use alternately specified directory funcs. */
144 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
145 
146 /*
147  * Error returns from "glob"
148  */
149 #define	GLOB_NOSYS	(-4)		/* function not supported (XPG4) */
150 #define	GLOB_NOMATCH	(-3)		/* Pattern does not match */
151 #define	GLOB_NOSPACE	(-2)		/* Not enough memory */
152 #define	GLOB_ABORTED	(-1)		/* GLOB_ERR set or errfunc return!=0 */
153 #define	GLOB_ABEND	GLOB_ABORTED	/* backward compatibility */
154 
155 #ifdef __PRAGMA_REDEFINE_EXTNAME
156 #pragma	redefine_extname	glob	_glob_ext
157 #pragma	redefine_extname	globfree	_globfree_ext
158 #else /* __PRAGMA_REDEFINE_EXTNAME */
159 #define	glob	_glob_ext
160 #define	globfree	_globfree_ext
161 #endif /* __PRAGMA_REDEFINE_EXTNAME */
162 
163 extern int glob(const char *_RESTRICT_KYWD, int, int(*)(const char *, int),
164 		glob_t *_RESTRICT_KYWD);
165 extern void globfree(glob_t *);
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _GLOB_H */
172