From 27275e151dcadb42ddee5c85df2bdc92649bfdc6 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 22 Apr 2024 01:35:23 +0200 Subject: [PATCH] Fix bugs in glob(3). --- libc/glob/glob.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libc/glob/glob.c b/libc/glob/glob.c index 6b549cf3..8db9f0b9 100644 --- a/libc/glob/glob.c +++ b/libc/glob/glob.c @@ -302,8 +302,8 @@ int glob(const char* restrict pattern, const char* path = segment->prefix ? segment->prefix : "."; if ( errno == ENOMEM ) result = GLOB_NOSPACE; - else if ( (errfunc && errfunc(path, errno)) || - (flags & GLOB_ERR) ) + else if ( errno && ((errfunc && errfunc(path, errno)) || + (flags & GLOB_ERR)) ) result = GLOB_ABORTED; segment->done = true; continue; @@ -414,7 +414,7 @@ int glob(const char* restrict pattern, free(path); continue; } - if ( want_slash && path[size - 3] != '/' ) + if ( want_slash && is_dir && path[size - 3] != '/' ) path[size - 2] = '/', path[size - 1] = '\0'; if ( !exists ) {