glob.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* Copyright (C) 1991,92,95,96,97,98,2000,2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _GLOB_H
  16. #define _GLOB_H 1
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #undef __ptr_t
  21. #if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
  22. # if !defined __GLIBC__ || !defined __P
  23. # undef __P
  24. # undef __PMT
  25. # define __P(protos) protos
  26. # define __PMT(protos) protos
  27. # if !defined __GNUC__ || __GNUC__ < 2
  28. # undef __const
  29. # define __const const
  30. # endif
  31. # endif
  32. # define __ptr_t void *
  33. #else /* Not C++ or ANSI C. */
  34. # undef __P
  35. # undef __PMT
  36. # define __P(protos) ()
  37. # define __PMT(protos) ()
  38. # undef __const
  39. # define __const
  40. # define __ptr_t char *
  41. #endif /* C++ or ANSI C. */
  42. /* We need `size_t' for the following definitions. */
  43. #ifndef __size_t
  44. # if defined __GNUC__ && __GNUC__ >= 2
  45. typedef __SIZE_TYPE__ __size_t;
  46. # ifdef _XOPEN_SOURCE
  47. typedef __SIZE_TYPE__ size_t;
  48. # endif
  49. # else
  50. /* This is a guess. */
  51. typedef unsigned long int __size_t;
  52. # endif
  53. #else
  54. /* The GNU CC stddef.h version defines __size_t as empty. We need a real
  55. definition. */
  56. # undef __size_t
  57. # define __size_t size_t
  58. #endif
  59. /* Bits set in the FLAGS argument to `glob'. */
  60. #define GLOB_ERR (1 << 0)/* Return on read errors. */
  61. #define GLOB_MARK (1 << 1)/* Append a slash to each name. */
  62. #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
  63. #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
  64. #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
  65. #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
  66. #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
  67. #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
  68. #if (!defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _BSD_SOURCE \
  69. || defined _GNU_SOURCE)
  70. # define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
  71. # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
  72. # define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
  73. # define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
  74. # define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
  75. # define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
  76. # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
  77. if the user name is not available. */
  78. # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
  79. GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
  80. GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
  81. GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
  82. #else
  83. # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
  84. GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
  85. GLOB_PERIOD)
  86. #endif
  87. /* Error returns from `glob'. */
  88. #define GLOB_NOSPACE 1 /* Ran out of memory. */
  89. #define GLOB_ABORTED 2 /* Read error. */
  90. #define GLOB_NOMATCH 3 /* No matches found. */
  91. #define GLOB_NOSYS 4 /* Not implemented. */
  92. #ifdef _GNU_SOURCE
  93. /* Previous versions of this file defined GLOB_ABEND instead of
  94. GLOB_ABORTED. Provide a compatibility definition here. */
  95. # define GLOB_ABEND GLOB_ABORTED
  96. #endif
  97. /* Structure describing a globbing run. */
  98. #if !defined _AMIGA && !defined VMS /* Buggy compiler. */
  99. # ifdef _GNU_SOURCE
  100. struct stat;
  101. # endif
  102. #endif
  103. typedef struct
  104. {
  105. __size_t gl_pathc; /* Count of paths matched by the pattern. */
  106. char **gl_pathv; /* List of matched pathnames. */
  107. __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
  108. int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
  109. /* If the GLOB_ALTDIRFUNC flag is set, the following functions
  110. are used instead of the normal file access functions. */
  111. void (*gl_closedir) __PMT ((void *));
  112. #ifdef _GNU_SOURCE
  113. struct dirent *(*gl_readdir) __PMT ((void *));
  114. #else
  115. void *(*gl_readdir) __PMT ((void *));
  116. #endif
  117. __ptr_t (*gl_opendir) __PMT ((__const char *));
  118. #ifdef _GNU_SOURCE
  119. int (*gl_lstat) __PMT ((__const char *__restrict,
  120. struct stat *__restrict));
  121. int (*gl_stat) __PMT ((__const char *__restrict, struct stat *__restrict));
  122. #else
  123. int (*gl_lstat) __PMT ((__const char *__restrict, void *__restrict));
  124. int (*gl_stat) __PMT ((__const char *__restrict, void *__restrict));
  125. #endif
  126. } glob_t;
  127. #ifdef _LARGEFILE64_SOURCE
  128. # ifdef _GNU_SOURCE
  129. struct stat64;
  130. # endif
  131. typedef struct
  132. {
  133. __size_t gl_pathc;
  134. char **gl_pathv;
  135. __size_t gl_offs;
  136. int gl_flags;
  137. /* If the GLOB_ALTDIRFUNC flag is set, the following functions
  138. are used instead of the normal file access functions. */
  139. void (*gl_closedir) __PMT ((void *));
  140. # ifdef _GNU_SOURCE
  141. struct dirent64 *(*gl_readdir) __PMT ((void *));
  142. # else
  143. void *(*gl_readdir) __PMT ((void *));
  144. # endif
  145. __ptr_t (*gl_opendir) __PMT ((__const char *));
  146. # ifdef _GNU_SOURCE
  147. int (*gl_lstat) __PMT ((__const char *__restrict,
  148. struct stat64 *__restrict));
  149. int (*gl_stat) __PMT ((__const char *__restrict,
  150. struct stat64 *__restrict));
  151. # else
  152. int (*gl_lstat) __PMT ((__const char *__restrict, void *__restrict));
  153. int (*gl_stat) __PMT ((__const char *__restrict, void *__restrict));
  154. # endif
  155. } glob64_t;
  156. #endif
  157. #if _FILE_OFFSET_BITS == 64 && __GNUC__ < 2
  158. # define glob glob64
  159. # define globfree globfree64
  160. #endif
  161. /* Do glob searching for PATTERN, placing results in PGLOB.
  162. The bits defined above may be set in FLAGS.
  163. If a directory cannot be opened or read and ERRFUNC is not nil,
  164. it is called with the pathname that caused the error, and the
  165. `errno' value from the failing call; if it returns non-zero
  166. `glob' returns GLOB_ABEND; if it returns zero, the error is ignored.
  167. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
  168. Otherwise, `glob' returns zero. */
  169. #if _FILE_OFFSET_BITS != 64 || __GNUC__ < 2
  170. extern int glob __P ((__const char *__restrict __pattern, int __flags,
  171. int (*__errfunc) (__const char *, int),
  172. glob_t *__restrict __pglob));
  173. /* Free storage allocated in PGLOB by a previous `glob' call. */
  174. extern void globfree __P ((glob_t *__pglob));
  175. #else
  176. extern int glob __P ((__const char *__restrict __pattern, int __flags,
  177. int (*__errfunc) (__const char *, int),
  178. glob_t *__restrict __pglob)) __asm__ ("glob64");
  179. extern void globfree __P ((glob_t *__pglob)) __asm__ ("globfree64");
  180. #endif
  181. #ifdef _LARGEFILE64_SOURCE
  182. extern int glob64 __P ((__const char *__restrict __pattern, int __flags,
  183. int (*__errfunc) (__const char *, int),
  184. glob64_t *__restrict __pglob));
  185. extern void globfree64 __P ((glob64_t *__pglob));
  186. #endif
  187. #ifdef _GNU_SOURCE
  188. /* Return nonzero if PATTERN contains any metacharacters.
  189. Metacharacters can be quoted with backslashes if QUOTE is nonzero.
  190. This function is not part of the interface specified by POSIX.2
  191. but several programs want to use it. */
  192. extern int glob_pattern_p __P ((__const char *__pattern, int __quote));
  193. #endif
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. #endif /* glob.h */