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