diff options
| author | Bojan Novković <bnovkov@FreeBSD.org> | 2025-05-23 15:26:04 +0200 |
|---|---|---|
| committer | Bojan Novković <bnovkov@FreeBSD.org> | 2025-06-02 11:32:50 +0200 |
| commit | 1e0743f54d2d3624cd4de2167d373aa38597778e (patch) | |
| tree | 413692aa060b395b702f4566387d2ca33969b10e /include | |
| parent | 61d77e6c009544d1489078c16a5d22b27d25c91b (diff) | |
glob: Add blocks support
This change introduces the `glob_b` function which takes a block instead
of a function pointer.
Relnotes: yes
Sponsored by: Klara, Inc.
Inspired by: https://github.com/apple-oss-distributions/Libc
Differential Revision: https://reviews.freebsd.org/D50485
Diffstat (limited to 'include')
| -rw-r--r-- | include/glob.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/include/glob.h b/include/glob.h index dc86cdf99929..cbe99bfef6ed 100644 --- a/include/glob.h +++ b/include/glob.h @@ -50,8 +50,15 @@ typedef struct { size_t gl_offs; /* Reserved at beginning of gl_pathv. */ int gl_flags; /* Copy of flags parameter to glob. */ char **gl_pathv; /* List of paths matching pattern. */ - /* Copy of errfunc parameter to glob. */ - int (*gl_errfunc)(const char *, int); + /* Copy of error callback parameter to glob. */ + union { + int (*gl_errfunc)(const char *, int); +#ifdef __BLOCKS__ + int (^gl_errblk)(const char *, int); +#else + void *gl_errblk; +#endif + }; /* * Alternate filesystem access methods for glob; replacement @@ -90,6 +97,7 @@ typedef struct { #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ #define GLOB_LIMIT 0x1000 /* limit number of returned paths */ +#define _GLOB_ERR_BLOCK 0x08000000 /* (internal) error callback is a block */ /* source compatibility, these are the old names */ #define GLOB_MAXPATH GLOB_LIMIT @@ -99,6 +107,10 @@ typedef struct { __BEGIN_DECLS int glob(const char * __restrict, int, int (*)(const char *, int), glob_t * __restrict); +#ifdef __BLOCKS__ +int glob_b(const char * __restrict, int, + int (^)(const char *, int), glob_t * __restrict); +#endif void globfree(glob_t *); __END_DECLS |
