xref: /titanic_51/usr/src/lib/libast/common/include/glob.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin *                                                                      *
3da2e3ebdSchin *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5da2e3ebdSchin *                      and is licensed under the                       *
6da2e3ebdSchin *                  Common Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8da2e3ebdSchin *                                                                      *
9da2e3ebdSchin *                A copy of the License is available at                 *
10da2e3ebdSchin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11da2e3ebdSchin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12da2e3ebdSchin *                                                                      *
13da2e3ebdSchin *              Information and Software Systems Research               *
14da2e3ebdSchin *                            AT&T Research                             *
15da2e3ebdSchin *                           Florham Park NJ                            *
16da2e3ebdSchin *                                                                      *
17da2e3ebdSchin *                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
19da2e3ebdSchin *                   Phong Vo <kpv@research.att.com>                    *
20da2e3ebdSchin *                                                                      *
21da2e3ebdSchin ***********************************************************************/
22da2e3ebdSchin #pragma prototyped
23da2e3ebdSchin /*
24da2e3ebdSchin  * posix glob interface definitions with gnu extensions
25da2e3ebdSchin  */
26da2e3ebdSchin 
27da2e3ebdSchin #ifndef _GLOB_H
28da2e3ebdSchin #define _GLOB_H
29da2e3ebdSchin 
30da2e3ebdSchin #define GLOB_VERSION	20060717L
31da2e3ebdSchin 
32da2e3ebdSchin #include <stdlib.h>
33da2e3ebdSchin 
34da2e3ebdSchin struct dirent;
35da2e3ebdSchin struct stat;
36da2e3ebdSchin 
37da2e3ebdSchin struct _glob_;
38da2e3ebdSchin struct _globlist_;
39da2e3ebdSchin 
40da2e3ebdSchin typedef struct _glob_ glob_t;
41da2e3ebdSchin typedef struct _globlist_ globlist_t;
42da2e3ebdSchin 
43da2e3ebdSchin struct _globlist_
44da2e3ebdSchin {
45da2e3ebdSchin 	globlist_t*	gl_next;
46da2e3ebdSchin 	char*		gl_begin;
47da2e3ebdSchin 	unsigned char	gl_flags;
48da2e3ebdSchin 	char		gl_path[1];
49da2e3ebdSchin };
50da2e3ebdSchin 
51da2e3ebdSchin struct _glob_
52da2e3ebdSchin {
53da2e3ebdSchin 	size_t		gl_pathc;
54da2e3ebdSchin 	char**		gl_pathv;
55da2e3ebdSchin 	size_t		gl_offs;
56da2e3ebdSchin 	globlist_t*	gl_list;
57da2e3ebdSchin 	int		gl_flags;
58da2e3ebdSchin 
59da2e3ebdSchin 	/* GLOB_DISC data -- memset(&gl,0,sizeof(gl)) before using! */
60da2e3ebdSchin 
61da2e3ebdSchin 	const char*	gl_fignore;
62da2e3ebdSchin 	const char*	gl_suffix;
63da2e3ebdSchin 	unsigned char*	gl_intr;
64da2e3ebdSchin 
65da2e3ebdSchin 	int		gl_delim;
66da2e3ebdSchin 
67da2e3ebdSchin 	void*		gl_handle;
68da2e3ebdSchin 	void*		(*gl_diropen)(glob_t*, const char*);
69da2e3ebdSchin 	char*		(*gl_dirnext)(glob_t*, void*);
70da2e3ebdSchin 	void		(*gl_dirclose)(glob_t*, void*);
717c2fbfb3SApril Chin 	int		(*gl_type)(glob_t*, const char*, int);
727c2fbfb3SApril Chin 	int		(*gl_attr)(glob_t*, const char*, int);
73da2e3ebdSchin 
74da2e3ebdSchin 	/* gnu extensions -- but how do you synthesize dirent and stat? */
75da2e3ebdSchin 
76da2e3ebdSchin 	void*		(*gl_opendir)(const char*);
77da2e3ebdSchin 	struct dirent*	(*gl_readdir)(void*);
78da2e3ebdSchin 	void		(*gl_closedir)(void*);
79da2e3ebdSchin 	int		(*gl_stat)(const char*, struct stat*);
80da2e3ebdSchin 	int		(*gl_lstat)(const char*, struct stat*);
81da2e3ebdSchin 
82da2e3ebdSchin 	/* ast additions */
83da2e3ebdSchin 
84da2e3ebdSchin 	char*		(*gl_nextdir)(glob_t*, char*);
85da2e3ebdSchin 	unsigned long	gl_status;
86da2e3ebdSchin 	unsigned long	gl_version;
87da2e3ebdSchin 	unsigned short	gl_extra;
88da2e3ebdSchin 
89da2e3ebdSchin #ifdef _GLOB_PRIVATE_
90da2e3ebdSchin 	_GLOB_PRIVATE_
91da2e3ebdSchin #else
92da2e3ebdSchin 	char*		gl_pad[23];
93da2e3ebdSchin #endif
94da2e3ebdSchin 
95da2e3ebdSchin };
96da2e3ebdSchin 
97da2e3ebdSchin /* standard interface */
98da2e3ebdSchin #define GLOB_APPEND	0x0001		/* append to previous		*/
99da2e3ebdSchin #define GLOB_DOOFFS	0x0002		/* gl_offs defines argv offset	*/
100da2e3ebdSchin #define GLOB_ERR	0x0004		/* abort on error		*/
101da2e3ebdSchin #define GLOB_MARK	0x0008		/* append / to directories	*/
102da2e3ebdSchin #define GLOB_NOCHECK	0x0010		/* nomatch is original pattern	*/
103da2e3ebdSchin #define GLOB_NOESCAPE	0x0020		/* don't treat \ specially	*/
104da2e3ebdSchin #define GLOB_NOSORT	0x0040		/* don't sort the list		*/
105da2e3ebdSchin 
106da2e3ebdSchin /* extended interface */
107da2e3ebdSchin #define GLOB_STARSTAR	0x0080		/* enable [/]**[/] expansion	*/
108da2e3ebdSchin #define GLOB_BRACE	0x0100		/* enable {...} expansion	*/
109da2e3ebdSchin #define GLOB_ICASE	0x0200		/* ignore case on match		*/
110da2e3ebdSchin #define GLOB_COMPLETE	0x0400		/* shell file completeion	*/
111da2e3ebdSchin #define GLOB_AUGMENTED	0x0800		/* augmented shell patterns	*/
112da2e3ebdSchin #define GLOB_STACK	0x1000		/* allocate on current stack	*/
113da2e3ebdSchin #define GLOB_LIST	0x2000		/* just create gl_list		*/
114da2e3ebdSchin #define GLOB_ALTDIRFUNC	0x4000		/* gnu discipline functions	*/
115da2e3ebdSchin #define GLOB_DISC	0x8000		/* discipline initialized	*/
116da2e3ebdSchin 
117da2e3ebdSchin /* gl_status */
118da2e3ebdSchin #define GLOB_NOTDIR	0x0001		/* last gl_dirnext() not a dir	*/
119da2e3ebdSchin 
120da2e3ebdSchin /* gl_type return */
121da2e3ebdSchin #define GLOB_NOTFOUND	0		/* does not exist		*/
122da2e3ebdSchin #define GLOB_DEV	1		/* exists but not DIR EXE REG	*/
123da2e3ebdSchin #define GLOB_DIR	2		/* directory			*/
124da2e3ebdSchin #define GLOB_EXE	3		/* executable regular file	*/
125da2e3ebdSchin #define GLOB_REG	4		/* regular file			*/
126da2e3ebdSchin 
127da2e3ebdSchin /* error return values */
128da2e3ebdSchin #define GLOB_ABORTED	1
129da2e3ebdSchin #define GLOB_NOMATCH	2
130da2e3ebdSchin #define GLOB_NOSPACE	3
131da2e3ebdSchin #define GLOB_INTR	4
132da2e3ebdSchin #define GLOB_APPERR	5
133da2e3ebdSchin #define GLOB_NOSYS	6
134da2e3ebdSchin 
135da2e3ebdSchin #if _BLD_ast && defined(__EXPORT__)
136da2e3ebdSchin #define extern		__EXPORT__
137da2e3ebdSchin #endif
138da2e3ebdSchin 
139da2e3ebdSchin extern int	glob(const char*, int, int(*)(const char*,int), glob_t*);
140da2e3ebdSchin extern void	globfree(glob_t*);
141da2e3ebdSchin 
142da2e3ebdSchin #undef	extern
143da2e3ebdSchin 
144da2e3ebdSchin #endif /* _GLOB_H */
145