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