home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / h / glob < prev    next >
Encoding:
Text File  |  2006-09-17  |  3.7 KB  |  108 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/glob.h,v $
  4.  * $Date: 2004/10/17 16:24:43 $
  5.  * $Revision: 1.7 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. #ifndef __GLOB_H
  12. #define __GLOB_H 1
  13.  
  14. #ifndef __UNIXLIB_FEATURES_H
  15. #include <features.h>
  16. #endif
  17.  
  18. #define __need_size_t
  19. #include <stddef.h>
  20.  
  21. #undef __ptr_t
  22. #define __ptr_t void *
  23.  
  24. __BEGIN_DECLS
  25.  
  26. /* Bits set in the 'flags' argument to `glob'.  */
  27. #define    GLOB_ERR    (1 << 0)/* Return on read errors.  */
  28. #define    GLOB_MARK    (1 << 1)/* Append a slash to each name.  */
  29. #define    GLOB_NOSORT    (1 << 2)/* Don't sort the names.  */
  30. #define    GLOB_DOOFFS    (1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
  31. #define    GLOB_NOCHECK    (1 << 4)/* If nothing matches, return the pattern.  */
  32. #define    GLOB_APPEND    (1 << 5)/* Append to results of a previous call.  */
  33. #define    GLOB_NOESCAPE    (1 << 6)/* Backslashes don't quote metacharacters.  */
  34. #define    GLOB_PERIOD    (1 << 7)/* Leading `.' can be matched by metachars.  */
  35.  
  36. #if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU
  37. /* GNU and BSD extensions to the glob function.  */
  38. #define    GLOB_MAGCHAR    (1 << 8)/* Set in gl_flags if any metachars seen.  */
  39. #define GLOB_ALTDIRFUNC    (1 << 9)/* Use gl_opendir et al functions.  */
  40. #define GLOB_BRACE    (1 << 10)/* Expand "{a,b}" to "a" "b".  */
  41. #define GLOB_NOMAGIC    (1 << 11)/* If no magic chars, return the pattern.  */
  42. #define GLOB_TILDE    (1 << 12)/* Expand ~user and ~ to home directories.  */
  43. #define GLOB_QUOTE (1 << 13) /* \ inhibits any meaning the following char has */
  44. #define    __GLOB_FLAGS    (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
  45.              GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
  46.              GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE|     \
  47.              GLOB_NOMAGIC|GLOB_TILDE)
  48. #else
  49. #define __GLOB_FLAGS   (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
  50.                         GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
  51.                         GLOB_PERIOD)
  52. #endif
  53.  
  54. /* Error returns from `glob'.  */
  55. #define    GLOB_NOSPACE    1    /* Ran out of memory.  */
  56. #define GLOB_ABORTED    2    /* Read error.  */
  57. #define    GLOB_ABEND    2    /* Read error.  */
  58. #define    GLOB_NOMATCH    3    /* No matches found.  */
  59. #define GLOB_NOSYS    4    /* Not implemented.  */
  60.  
  61. /* Need the definition of struct stat.  */
  62. #ifdef __GNUC__
  63. struct stat;
  64. #else
  65. /* We should not do this, but Norcroft C complains about duplicate
  66.    definitions. */
  67. #ifndef __SYS_STAT_H
  68. #include <sys/stat.h>
  69. #endif
  70. #endif /* !__GNUC__ */
  71.  
  72. /* Structure describing a globbing run.  */
  73. typedef struct
  74.   {
  75.     /* Count of paths matched by the pattern.  */
  76.     size_t gl_pathc;
  77.     /* List of matched pathnames.  */
  78.     char **gl_pathv;
  79.     /* Slots to reserve in `gl_pathv'.  */
  80.     size_t gl_offs;
  81.     /* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
  82.     int gl_flags;
  83.     /* Number of matches in current invoc. of glob */
  84.     int gl_matchc;
  85.  
  86.     /* If the GLOB_ALTDIRFUNC flag is set, the following functions
  87.        are used instead of the normal file access functions.  */
  88.     void (*gl_closedir) (void *);
  89.     struct dirent *(*gl_readdir) (void *);
  90.     __ptr_t (*gl_opendir) (const char *);
  91.     int (*gl_lstat) (const char *__restrict, struct stat *__restrict);
  92.     int (*gl_stat) (const char *__restrict, struct stat *__restrict);
  93.     int (*gl_errfunc) (const char *, int);
  94.   } glob_t;
  95.  
  96. /* Do glob searching for 'pattern'. Results will be placed in 'pglob'.
  97.    'errfunc' is called upon error.  Returns zero on success.  */
  98. extern int glob (const char *__restrict __pattern, int __flags,
  99.          int (*__errfunc) (const char *, int),
  100.          glob_t *__restrict __pglob) __THROW;
  101.  
  102. /* Free storage allocated in 'pglob' by a previous call to glob.  */
  103. extern void globfree (glob_t *__pglob) __THROW;
  104.  
  105. __END_DECLS
  106.  
  107. #endif
  108.