summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-11-09 13:25:49 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-11-21 08:47:38 +0100
commit1c04c0e3289943a07d9f6bbef73edceaa96d3091 (patch)
tree761ff01b0c919eb07726018aba74c6ec0d59bc53 /lib
parent401ba0a3214109c6eb35284874b4621599c98f3e (diff)
downloadbarebox-1c04c0e3289943a07d9f6bbef73edceaa96d3091.tar.gz
barebox-1c04c0e3289943a07d9f6bbef73edceaa96d3091.tar.xz
glob: drop needless ifdeffery in {glob,fnmatch}.h
The implementation of the glob and fnmatch functions is taken from glibc and it shows in the amount of #ifdefs. We don't need that in barebox and can even get the glob_t size down by dropping unused members, so let's do that. Cc: Christian Melki <christian.melki@t2data.com> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231109122551.1486020-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile2
-rw-r--r--lib/fnmatch.c45
-rw-r--r--lib/glob.c107
3 files changed, 20 insertions, 134 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 791080b2d1..ab9f476041 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -38,7 +38,7 @@ obj-$(CONFIG_CMDLINE_EDITING) += readline.o
obj-$(CONFIG_SIMPLE_READLINE) += readline_simple.o
obj-$(CONFIG_FNMATCH) += fnmatch.o
obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
-obj-y += glob.o
+obj-$(CONFIG_GLOB) += glob.o
obj-y += notifier.o
obj-y += random.o
obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 0ab530d3b1..ac87ba7621 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -1,50 +1,11 @@
-/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with this library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
-
-/* Enable GNU extensions in fnmatch.h. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// SPDX-FileCopyrightText: (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
#include <errno.h>
#include <fnmatch.h>
#include <linux/ctype.h>
-
-/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself. This code is part of the GNU C
- Library, but also included in many other GNU distributions. Compiling
- and linking in this code is a waste when using the GNU C library
- (especially if it is a shared library). Rather than having every GNU
- program understand `configure --with-gnu-libc' and omit the object files,
- it is simpler to just do this in the source for each such file. */
-
-# if defined (STDC_HEADERS) || !defined (isascii)
-# define ISASCII(c) 1
-# else
-# define ISASCII(c) isascii(c)
-# endif
-
-# define ISUPPER(c) (ISASCII (c) && isupper (c))
-
-
-# ifndef errno
-extern int errno;
-# endif
+# define ISUPPER(c) (isascii(c) && isupper(c))
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
diff --git a/lib/glob.c b/lib/glob.c
index 8523bad9a7..389580b0ed 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -1,19 +1,5 @@
-/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with this library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// SPDX-FileCopyrightText: (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
#include <common.h>
#include <errno.h>
@@ -23,25 +9,15 @@ Cambridge, MA 02139, USA. */
#include <xfuncs.h>
#include <fnmatch.h>
#include <qsort.h>
-#define _GNU_SOURCE
#include <glob.h>
-#ifdef CONFIG_GLOB
-
-extern __ptr_t(*__glob_opendir_hook) __P((const char *directory));
-extern void (*__glob_closedir_hook) __P((__ptr_t stream));
-extern const char *(*__glob_readdir_hook) __P((__ptr_t stream));
-
-static int glob_in_dir __P((const char *pattern, const char *directory,
+static int glob_in_dir (const char *pattern, const char *directory,
int flags,
- int (*errfunc) __P((const char *, int)),
- glob_t * pglob));
-static int prefix_array __P((const char *prefix, char **array, size_t n,
- int add_slash));
-
-#ifdef __GLOB64
-extern int glob_pattern_p(const char *pattern, int quote);
-#else
+ int (*errfunc) (const char *, int),
+ glob_t * pglob);
+static int prefix_array (const char *prefix, char **array, size_t n,
+ int add_slash);
+
/* Return nonzero if PATTERN contains any metacharacters.
Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
int glob_pattern_p(const char *pattern, int quote)
@@ -72,7 +48,6 @@ int glob_pattern_p(const char *pattern, int quote)
return 0;
}
-#endif
#ifdef CONFIG_GLOB_SORT
/* Do a collated comparison of A and B. */
@@ -100,7 +75,7 @@ static int collated_compare(const void *a, const void *b)
If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
Otherwise, `glob' returns zero. */
int glob(const char *pattern, int flags,
- int (*errfunc) __P((const char *, int)), glob_t *pglob)
+ int (*errfunc) (const char *, int), glob_t *pglob)
{
const char *filename;
char *dirname = NULL;
@@ -169,19 +144,6 @@ int glob(const char *pattern, int flags,
for (i = 0; i < dirs.gl_pathc; ++i) {
int oldcount1;
-#ifdef SHELL
- {
- /* Make globbing interruptible in the bash shell. */
- extern int interrupt_state;
-
- if (interrupt_state) {
- globfree(&dirs);
- globfree(&files);
- status = GLOB_ABEND goto out;
- }
- }
-#endif /* SHELL. */
-
oldcount1 = pglob->gl_pathc;
status = glob_in_dir(filename, dirs.gl_pathv[i],
(flags | GLOB_APPEND) &
@@ -263,7 +225,7 @@ int glob(const char *pattern, int flags,
#ifdef CONFIG_GLOB_SORT
if (!(flags & GLOB_NOSORT))
/* Sort the vector. */
- qsort((__ptr_t) & pglob->gl_pathv[oldcount],
+ qsort(&pglob->gl_pathv[oldcount],
pglob->gl_pathc - oldcount,
sizeof(char *), collated_compare);
#endif
@@ -299,7 +261,7 @@ static int prefix_array(const char *dirname, char **array, size_t n,
memcpy(new, dirname, dirlen);
new[dirlen] = '/';
memcpy(&new[dirlen + 1], array[i], eltlen);
- free((__ptr_t) array[i]);
+ free(array[i]);
array[i] = new;
}
@@ -311,9 +273,9 @@ static int prefix_array(const char *dirname, char **array, size_t n,
The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done.
The GLOB_APPEND flag is assumed to be set (always appends). */
static int glob_in_dir(const char *pattern, const char *directory,
- int flags, int (*errfunc) __P((const char *, int)), glob_t *pglob)
+ int flags, int (*errfunc) (const char *, int), glob_t *pglob)
{
- __ptr_t stream = NULL;
+ void *stream = NULL;
struct globlink {
struct globlink *next;
@@ -356,7 +318,7 @@ static int glob_in_dir(const char *pattern, const char *directory,
(struct globlink *)xmalloc(sizeof(struct globlink));
len = strlen(name);
new->name = xmalloc(len + ((flags & GLOB_MARK) ? 1 : 0) + 1);
- memcpy((__ptr_t) new->name, name, len);
+ memcpy(new->name, name, len);
new->name[len] = '\0';
new->next = names;
names = new;
@@ -414,44 +376,7 @@ void globfree(glob_t *pglob)
int i = pglob->gl_flags & GLOB_DOOFFS ? pglob->gl_offs : 0;
for (; i < pglob->gl_pathc; ++i)
if (pglob->gl_pathv[i] != NULL)
- free((__ptr_t) pglob->gl_pathv[i]);
- free((__ptr_t) pglob->gl_pathv);
- }
-}
-#endif /* CONFIG_GLOB */
-
-#ifdef CONFIG_FAKE_GLOB
-/* Fake version of glob. We simply put the input string into
- * the gl_pathv array. Currently we don't need it as hush.c won't
- * call us if no glob support is available.
- */
-int glob(pattern, flags, errfunc, pglob)
-const char *pattern;
-int flags;
-int (*errfunc) __P((const char *, int));
-glob_t *pglob;
-{
- int elems, i;
-
- if (!(flags & GLOB_APPEND)) {
- pglob->gl_pathc = 0;
- pglob->gl_pathv = NULL;
+ free(pglob->gl_pathv[i]);
+ free(pglob->gl_pathv);
}
-
- elems = pglob->gl_pathc + 2;
- if (flags & GLOB_DOOFFS)
- elems += pglob->gl_offs;
-
- pglob->gl_pathv = xrealloc(pglob->gl_pathv, elems * sizeof(char *));
-
- if (flags & GLOB_DOOFFS)
- for (i = 0; i < pglob->gl_offs; i++)
- pglob->gl_pathv[i] = NULL;
-
- pglob->gl_pathv[pglob->gl_pathc] = strdup(pattern);
- pglob->gl_pathc++;
- pglob->gl_pathv[pglob->gl_pathc] = NULL;
-
- return 0;
}
-#endif /* CONFIG_FAKE_GLOB */