Fix bugs in glob(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2024-04-22 01:35:23 +02:00
parent a7f5ac82aa
commit 27275e151d
1 changed files with 3 additions and 3 deletions

View File

@ -302,8 +302,8 @@ int glob(const char* restrict pattern,
const char* path = segment->prefix ? segment->prefix : "."; const char* path = segment->prefix ? segment->prefix : ".";
if ( errno == ENOMEM ) if ( errno == ENOMEM )
result = GLOB_NOSPACE; result = GLOB_NOSPACE;
else if ( (errfunc && errfunc(path, errno)) || else if ( errno && ((errfunc && errfunc(path, errno)) ||
(flags & GLOB_ERR) ) (flags & GLOB_ERR)) )
result = GLOB_ABORTED; result = GLOB_ABORTED;
segment->done = true; segment->done = true;
continue; continue;
@ -414,7 +414,7 @@ int glob(const char* restrict pattern,
free(path); free(path);
continue; continue;
} }
if ( want_slash && path[size - 3] != '/' ) if ( want_slash && is_dir && path[size - 3] != '/' )
path[size - 2] = '/', path[size - 1] = '\0'; path[size - 2] = '/', path[size - 1] = '\0';
if ( !exists ) if ( !exists )
{ {