From fb78d87b33ab0380fbfddd539959225cb1f7c1f2 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jun 2018 17:39:38 +0300 Subject: lib: glob: Fix compilation The glibc glob() implementation seems to be meant to be compilable outside of glibc, but that clearly hasn't been tested for some time. Fix compilation. Signed-off-by: Laurent Pinchart --- lib/compat/glob.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/compat/glob.c b/lib/compat/glob.c index c653809..e48b030 100644 --- a/lib/compat/glob.c +++ b/lib/compat/glob.c @@ -19,6 +19,11 @@ # include #endif +#define _GNU_SOURCE +#define __glibc_unlikely(x) x +#define __libc_use_alloca(x) 0 +#define alloca_account(size, avar) alloca(size) + #include #include @@ -93,10 +98,7 @@ # endif # define struct_stat64 struct stat64 #else /* !_LIBC */ -# include "getlogin_r.h" -# include "mempcpy.h" -# include "stat-macros.h" -# include "strdup.h" +# include # define __stat64(fname, buf) stat (fname, buf) # define struct_stat64 struct stat # define __stat(fname, buf) stat (fname, buf) @@ -104,6 +106,8 @@ # define __readdir readdir # define __readdir64 readdir64 # define __glob_pattern_p glob_pattern_p +# define __getlogin_r(buf, len) getlogin_r(buf, len) +# define __strdup(str) strdup (str) #endif /* _LIBC */ #include @@ -292,9 +296,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), int malloc_dirname = 0; glob_t dirs; int retval = 0; -#ifdef _LIBC size_t alloca_used = 0; -#endif if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) { @@ -700,8 +702,11 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), # endif if (p != NULL) { +# if defined HAVE_GETPWNAM_R || defined _LIBC if (!malloc_pwtmpbuf) +# endif home_dir = p->pw_dir; +# if defined HAVE_GETPWNAM_R || defined _LIBC else { size_t home_dir_len = strlen (p->pw_dir) + 1; @@ -723,6 +728,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), free (pwtmpbuf); } +# endif } } } @@ -931,8 +937,10 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), dirname = malloc (home_len + rest_len + 1); if (dirname == NULL) { +# if defined HAVE_GETPWNAM_R || defined _LIBC if (__glibc_unlikely (malloc_pwtmpbuf)) free (pwtmpbuf); +# endif retval = GLOB_NOSPACE; goto out; } @@ -944,13 +952,17 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), dirlen = home_len + rest_len; dirname_modified = 1; +# if defined HAVE_GETPWNAM_R || defined _LIBC if (__glibc_unlikely (malloc_pwtmpbuf)) free (pwtmpbuf); +# endif } else { +# if defined HAVE_GETPWNAM_R || defined _LIBC if (__glibc_unlikely (malloc_pwtmpbuf)) free (pwtmpbuf); +# endif if (flags & GLOB_TILDE_CHECK) /* We have to regard it as an error if we cannot find the -- cgit v1.2.3