home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / h / glob < prev    next >
Encoding:
Text File  |  2004-09-05  |  3.4 KB  |  99 lines

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