xref: /illumos-gate/usr/src/head/glob.h (revision 33e8313d)
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  */
22a5229c74SGary Mills 
237c478bd9Sstevel@tonic-gate /*
24ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25a5229c74SGary Mills  * Copyright 1985, 1992 by Mortice Kern Systems Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
29a5229c74SGary Mills  * Copyright (c) 1989, 1993
30a5229c74SGary Mills  *	The Regents of the University of California.  All rights reserved.
31a5229c74SGary Mills  *
32a5229c74SGary Mills  * This code is derived from software contributed to Berkeley by
33a5229c74SGary Mills  * Guido van Rossum.
34a5229c74SGary Mills  *
35a5229c74SGary Mills  * Redistribution and use in source and binary forms, with or without
36a5229c74SGary Mills  * modification, are permitted provided that the following conditions
37a5229c74SGary Mills  * are met:
38a5229c74SGary Mills  * 1. Redistributions of source code must retain the above copyright
39a5229c74SGary Mills  *    notice, this list of conditions and the following disclaimer.
40a5229c74SGary Mills  * 2. Redistributions in binary form must reproduce the above copyright
41a5229c74SGary Mills  *    notice, this list of conditions and the following disclaimer in the
42a5229c74SGary Mills  *    documentation and/or other materials provided with the distribution.
43a5229c74SGary Mills  * 3. Neither the name of the University nor the names of its contributors
44a5229c74SGary Mills  *    may be used to endorse or promote products derived from this software
45a5229c74SGary Mills  *    without specific prior written permission.
46a5229c74SGary Mills  *
47a5229c74SGary Mills  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48a5229c74SGary Mills  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49a5229c74SGary Mills  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50a5229c74SGary Mills  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51a5229c74SGary Mills  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52a5229c74SGary Mills  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53a5229c74SGary Mills  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54a5229c74SGary Mills  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55a5229c74SGary Mills  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56a5229c74SGary Mills  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57a5229c74SGary Mills  * SUCH DAMAGE.
58a5229c74SGary Mills  *
59a5229c74SGary Mills  *	@(#)glob.h	8.1 (Berkeley) 6/2/93
60a5229c74SGary Mills  */
61a5229c74SGary Mills 
62a5229c74SGary Mills /*
63a5229c74SGary Mills  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
64a5229c74SGary Mills  * Use is subject to license terms.
65a5229c74SGary Mills  * Copyright (c) 2013 Gary Mills
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifndef	_GLOB_H
697c478bd9Sstevel@tonic-gate #define	_GLOB_H
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
727c478bd9Sstevel@tonic-gate #include <sys/types.h>
73a5229c74SGary Mills #include <sys/stat.h>
74a5229c74SGary Mills #include <dirent.h>
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
777c478bd9Sstevel@tonic-gate extern "C" {
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef	struct	glob_t	{
81a5229c74SGary Mills 	/*
82a5229c74SGary Mills 	 * Members specified by POSIX
83a5229c74SGary Mills 	 */
84a5229c74SGary Mills 	size_t	gl_pathc;	/* Total count of paths matched by pattern */
85a5229c74SGary Mills 	char	**gl_pathv;	/* List of matched pathnames */
86a5229c74SGary Mills 	size_t	gl_offs;	/* # of slots reserved in gl_pathv */
87a5229c74SGary Mills 
88a5229c74SGary Mills 	/*
89a5229c74SGary Mills 	 * Internal-use members:
90a5229c74SGary Mills 	 *
91a5229c74SGary Mills 	 * NB: The next two members are carried in both the
92a5229c74SGary Mills 	 * libc backward compatibility wrapper functions and
93a5229c74SGary Mills 	 * the extended functions.
94a5229c74SGary Mills 	 */
95a5229c74SGary Mills 	char	**gl_pathp;	/* gl_pathv + gl_offs */
96a5229c74SGary Mills 	int	gl_pathn;	/* # of elements allocated */
97a5229c74SGary Mills 
98a5229c74SGary Mills 	/*
99a5229c74SGary Mills 	 * Non-POSIX extensions
100a5229c74SGary Mills 	 *
101a5229c74SGary Mills 	 * NB: The following members are not carried in
102a5229c74SGary Mills 	 * the libc backward compatibility wrapper functions.
103a5229c74SGary Mills 	 */
104a5229c74SGary Mills 	int	gl_matchc;	/* Count of paths matching pattern. */
105a5229c74SGary Mills 	int	gl_flags;	/* Copy of flags parameter to glob. */
106a5229c74SGary Mills 	struct	stat **gl_statv; /* Stat entries corresponding to gl_pathv */
107a5229c74SGary Mills 
108a5229c74SGary Mills 	/*
109a5229c74SGary Mills 	 * Alternate filesystem access methods for glob; replacement
110a5229c74SGary Mills 	 * versions of closedir(3), readdir(3), opendir(3), stat(2)
111a5229c74SGary Mills 	 * and lstat(2).
112a5229c74SGary Mills 	 */
113a5229c74SGary Mills 	void (*gl_closedir)(void *);
114a5229c74SGary Mills 	struct dirent *(*gl_readdir)(void *);
115a5229c74SGary Mills 	void *(*gl_opendir)(const char *);
116a5229c74SGary Mills 	int (*gl_lstat)(const char *, struct stat *);
117a5229c74SGary Mills 	int (*gl_stat)(const char *, struct stat *);
1187c478bd9Sstevel@tonic-gate }	glob_t;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
121a5229c74SGary Mills  * POSIX "flags" argument to glob function.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate #define	GLOB_ERR	0x0001		/* Don't continue on directory error */
1247c478bd9Sstevel@tonic-gate #define	GLOB_MARK	0x0002		/* Mark directories with trailing / */
1257c478bd9Sstevel@tonic-gate #define	GLOB_NOSORT	0x0004		/* Don't sort pathnames */
1267c478bd9Sstevel@tonic-gate #define	GLOB_NOCHECK	0x0008		/* Return unquoted arg if no match */
1277c478bd9Sstevel@tonic-gate #define	GLOB_DOOFFS	0x0010		/* Ignore gl_offs unless set */
1287c478bd9Sstevel@tonic-gate #define	GLOB_APPEND	0x0020		/* Append to previous glob_t */
1297c478bd9Sstevel@tonic-gate #define	GLOB_NOESCAPE	0x0040		/* Backslashes do not quote M-chars */
1307c478bd9Sstevel@tonic-gate 
131a5229c74SGary Mills /*
132a5229c74SGary Mills  * Non-POSIX "flags" argument to glob function, from OpenBSD.
133a5229c74SGary Mills  */
134a5229c74SGary Mills #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
135a5229c74SGary Mills #define	GLOB_POSIX	0x007F	/* All POSIX flags */
136a5229c74SGary Mills #define	GLOB_BRACE	0x0080	/* Expand braces ala csh. */
137a5229c74SGary Mills #define	GLOB_MAGCHAR	0x0100	/* Pattern had globbing characters. */
138a5229c74SGary Mills #define	GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
139a5229c74SGary Mills #define	GLOB_QUOTE	0x0400	/* Quote special chars with \. */
140a5229c74SGary Mills #define	GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
141a5229c74SGary Mills #define	GLOB_LIMIT	0x2000	/* Limit pattern match output to ARG_MAX */
142a5229c74SGary Mills #define	GLOB_KEEPSTAT	0x4000	/* Retain stat data for paths in gl_statv. */
143a5229c74SGary Mills #define	GLOB_ALTDIRFUNC	0x8000	/* Use alternately specified directory funcs. */
144a5229c74SGary Mills #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
145a5229c74SGary Mills 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Error returns from "glob"
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate #define	GLOB_NOSYS	(-4)		/* function not supported (XPG4) */
1507c478bd9Sstevel@tonic-gate #define	GLOB_NOMATCH	(-3)		/* Pattern does not match */
1517c478bd9Sstevel@tonic-gate #define	GLOB_NOSPACE	(-2)		/* Not enough memory */
1527c478bd9Sstevel@tonic-gate #define	GLOB_ABORTED	(-1)		/* GLOB_ERR set or errfunc return!=0 */
153a5229c74SGary Mills #define	GLOB_ABEND	GLOB_ABORTED	/* backward compatibility */
154a5229c74SGary Mills 
155*33e8313dSRobert Mustacchi 
156a5229c74SGary Mills #ifdef __PRAGMA_REDEFINE_EXTNAME
157*33e8313dSRobert Mustacchi #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
158*33e8313dSRobert Mustacchi #pragma	redefine_extname	glob	_glob_ext64
159*33e8313dSRobert Mustacchi #pragma	redefine_extname	globfree	_globfree_ext64
160*33e8313dSRobert Mustacchi #else
161a5229c74SGary Mills #pragma	redefine_extname	glob	_glob_ext
162a5229c74SGary Mills #pragma	redefine_extname	globfree	_globfree_ext
163*33e8313dSRobert Mustacchi #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
164a5229c74SGary Mills #else /* __PRAGMA_REDEFINE_EXTNAME */
165*33e8313dSRobert Mustacchi #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
166*33e8313dSRobert Mustacchi #define	glob	_glob_ext64
167*33e8313dSRobert Mustacchi #define	globfree	_globfree_ext64
168*33e8313dSRobert Mustacchi #else
169a5229c74SGary Mills #define	glob	_glob_ext
170a5229c74SGary Mills #define	globfree	_globfree_ext
171*33e8313dSRobert Mustacchi #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
172a5229c74SGary Mills #endif /* __PRAGMA_REDEFINE_EXTNAME */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate extern int glob(const char *_RESTRICT_KYWD, int, int(*)(const char *, int),
1757c478bd9Sstevel@tonic-gate 		glob_t *_RESTRICT_KYWD);
1767c478bd9Sstevel@tonic-gate extern void globfree(glob_t *);
177a5229c74SGary Mills 
1787c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate #endif
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #endif	/* _GLOB_H */
183