From 765c836c3d83e6eb4bbcb0058f742f793ee4dc82 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 17 Apr 2019 17:13:09 +0200 Subject: [PATCH] Remove dependency on libbsd Signed-off-by: David Oberhollenzer --- configure.ac | 4 ---- sqfs/Makemodule.am | 6 ----- sqfs/pkg2sqfs.c | 55 +++++++++++++++++++++++++++++++++++++++++----- sqfs/pkg2sqfs.h | 9 ++++---- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 51feb93..5377012 100644 --- a/configure.ac +++ b/configure.ac @@ -50,10 +50,6 @@ PKG_CHECK_MODULES(XZ, [liblzma >= 5.0.0], [have_lzma="yes"], []) AM_CONDITIONAL([WITH_ZLIB], [test "x$have_zlib" == "xyes"]) AM_CONDITIONAL([WITH_LZMA], [test "x$have_lzma" == "xyes"]) -AM_CONDITIONAL([HAVE_LIBBSD], [true]) -PKG_CHECK_MODULES(LIBBSD, [libbsd], [], - [AC_MSG_ERROR([missing libbsd])]) - ##### generate output ##### AC_CONFIG_HEADERS([config.h]) diff --git a/sqfs/Makemodule.am b/sqfs/Makemodule.am index 881fabc..ce0cbda 100644 --- a/sqfs/Makemodule.am +++ b/sqfs/Makemodule.am @@ -13,10 +13,4 @@ if WITH_ZLIB pkg2sqfs_LDADD += $(ZLIB_LIBS) endif -if HAVE_LIBBSD -pkg2sqfs_CPPFLAGS += -DHAVE_LIBBSD -pkg2sqfs_CFLAGS += $(LIBBSD_CFLAGS) -pkg2sqfs_LDADD += $(LIBBSD_LIBS) -endif - bin_PROGRAMS += pkg2sqfs diff --git a/sqfs/pkg2sqfs.c b/sqfs/pkg2sqfs.c index 3ce5432..12688ab 100644 --- a/sqfs/pkg2sqfs.c +++ b/sqfs/pkg2sqfs.c @@ -87,16 +87,59 @@ static void print_tree(int level, node_t *n) static long read_number(const char *name, const char *str, long min, long max) { - const char *errstr; - long result; + long base = 10, result = 0; + int x; - result = strtonum(str, min, max, &errstr); - if (errstr != NULL) { - fprintf(stderr, "%s '%s': %s\n", name, str, errstr); - exit(EXIT_FAILURE); + if (str[0] == '0') { + if (str[1] == 'x' || str[1] == 'X') { + base = 16; + str += 2; + } else { + base = 8; + } } + if (!isxdigit(*str)) + goto fail_num; + + while (isxdigit(*str)) { + x = *(str++); + + if (isupper(x)) { + x = x - 'A' + 10; + } else if (islower(x)) { + x = x - 'a' + 10; + } else { + x -= '0'; + } + + if (x >= base) + goto fail_num; + + if (result > (LONG_MAX - x) / base) + goto fail_ov; + + result = result * base + x; + } + + if (result < min) + goto fail_uf; + + if (result > max) + goto fail_ov; + return result; +fail_num: + fprintf(stderr, "%s: expected numeric value > 0\n", name); + goto fail; +fail_uf: + fprintf(stderr, "%s: number to small\n", name); + goto fail; +fail_ov: + fprintf(stderr, "%s: number to large\n", name); + goto fail; +fail: + exit(EXIT_FAILURE); } static int sqfs_padd_file(sqfs_info_t *info) diff --git a/sqfs/pkg2sqfs.h b/sqfs/pkg2sqfs.h index bd9e878..2ebf79f 100644 --- a/sqfs/pkg2sqfs.h +++ b/sqfs/pkg2sqfs.h @@ -3,19 +3,20 @@ #define PKG2SQFS_H #include +#include #include #include #include #include #include #include +#include +#include +#include #include #include #include - -#ifdef HAVE_LIBBSD -#include -#endif +#include #include "util/util.h"