On Mon, Jun 02, 2025 at 09:33:14AM +0000, Bojan Novković wrote:
> The branch main has been updated by bnovkov:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=1e0743f54d2d3624cd4de2167d373aa38597778e
>
> commit 1e0743f54d2d3624cd4de2167d373aa38597778e
> Author: Bojan Novković <bnov...@freebsd.org>
> AuthorDate: 2025-05-23 13:26:04 +0000
> Commit: Bojan Novković <bnov...@freebsd.org>
> CommitDate: 2025-06-02 09:32:50 +0000
>
> 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
> ---
> include/glob.h | 16 +++++++++--
> lib/libc/gen/Makefile.inc | 1 +
> lib/libc/gen/Symbol.map | 1 +
> lib/libc/gen/glob.3 | 66 ++++++++++++++++++++++++++++++++++++++------
> lib/libc/gen/glob.c | 70
> +++++++++++++++++++++++++++++++++++++----------
> 5 files changed, 128 insertions(+), 26 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
glob.h is POSIX header, the non-standard prototype visibility must be limited.