aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/Makemodule.am5
-rw-r--r--lib/sqfs/block_processor/internal.h2
-rw-r--r--lib/sqfs/comp/internal.h2
-rw-r--r--lib/sqfs/str_table.h51
-rw-r--r--lib/sqfs/util.h31
-rw-r--r--lib/util/Makemodule.am6
-rw-r--r--lib/util/alloc.c (renamed from lib/sqfs/alloc.c)0
-rw-r--r--lib/util/str_table.c (renamed from lib/sqfs/str_table.c)0
8 files changed, 11 insertions, 86 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index aada6c6..591eda2 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -24,8 +24,6 @@ libsquashfs_la_SOURCES += lib/sqfs/write_super.c lib/sqfs/data_reader.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/internal.h
libsquashfs_la_SOURCES += lib/sqfs/block_processor/common.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/xxhash.c
-libsquashfs_la_SOURCES += lib/sqfs/str_table.c lib/sqfs/str_table.h
-libsquashfs_la_SOURCES += lib/sqfs/alloc.c lib/sqfs/util.h
libsquashfs_la_SOURCES += lib/sqfs/frag_table.c include/sqfs/frag_table.h
libsquashfs_la_SOURCES += lib/sqfs/block_writer.c include/sqfs/block_writer.h
libsquashfs_la_CPPFLAGS = $(AM_CPPFLAGS)
@@ -36,6 +34,9 @@ libsquashfs_la_CFLAGS += $(ZSTD_CFLAGS) $(PTHREAD_CFLAGS)
libsquashfs_la_LIBADD = $(XZ_LIBS) $(ZLIB_LIBS) $(LZ4_LIBS)
libsquashfs_la_LIBADD += $(ZSTD_LIBS) $(PTHREAD_LIBS)
+# directly "import" stuff from libutil
+libsquashfs_la_SOURCES += lib/util/str_table.c lib/util/alloc.c
+
if WINDOWS
libsquashfs_la_SOURCES += lib/sqfs/win32/io_file.c
libsquashfs_la_CFLAGS += -DWINVER=0x0600 -D_WIN32_WINNT=0x0600
diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h
index fb9c4a0..03a8296 100644
--- a/lib/sqfs/block_processor/internal.h
+++ b/lib/sqfs/block_processor/internal.h
@@ -18,7 +18,7 @@
#include "sqfs/error.h"
#include "sqfs/block.h"
#include "sqfs/io.h"
-#include "../util.h"
+#include "util.h"
#include <string.h>
#include <stdlib.h>
diff --git a/lib/sqfs/comp/internal.h b/lib/sqfs/comp/internal.h
index c687d41..7518f56 100644
--- a/lib/sqfs/comp/internal.h
+++ b/lib/sqfs/comp/internal.h
@@ -14,7 +14,7 @@
#include "sqfs/error.h"
#include "sqfs/block.h"
#include "sqfs/io.h"
-#include "../util.h"
+#include "util.h"
SQFS_INTERNAL
int sqfs_generic_write_options(sqfs_file_t *file, const void *data,
diff --git a/lib/sqfs/str_table.h b/lib/sqfs/str_table.h
deleted file mode 100644
index 61f8aa5..0000000
--- a/lib/sqfs/str_table.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * str_table.h
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#ifndef STR_TABLE_H
-#define STR_TABLE_H
-
-#include "sqfs/predef.h"
-
-typedef struct str_bucket_t {
- struct str_bucket_t *next;
- char *str;
- size_t index;
- size_t refcount;
-} str_bucket_t;
-
-/* Stores strings in a hash table and assigns an incremental, unique ID to
- each string. Subsequent additions return the existing ID. The ID can be
- used for (hopefully) constant time lookup of the original string. */
-typedef struct {
- str_bucket_t **buckets;
- size_t num_buckets;
-
- char **strings;
- size_t num_strings;
- size_t max_strings;
-} str_table_t;
-
-/* `size` is the number of hash table buckets to use internally. */
-SQFS_INTERNAL int str_table_init(str_table_t *table, size_t size);
-
-SQFS_INTERNAL void str_table_cleanup(str_table_t *table);
-
-/* Resolve a string to an incremental, unique ID. */
-SQFS_INTERNAL
-int str_table_get_index(str_table_t *table, const char *str, size_t *idx);
-
-/* Resolve a unique ID to the string it represents.
- Returns NULL if the ID is unknown, i.e. out of bounds. */
-SQFS_INTERNAL
-const char *str_table_get_string(str_table_t *table, size_t index);
-
-SQFS_INTERNAL void str_table_add_ref(str_table_t *table, size_t index);
-
-SQFS_INTERNAL void str_table_del_ref(str_table_t *table, size_t index);
-
-SQFS_INTERNAL size_t str_table_get_ref_count(str_table_t *table, size_t index);
-
-#endif /* STR_TABLE_H */
diff --git a/lib/sqfs/util.h b/lib/sqfs/util.h
deleted file mode 100644
index a379c0d..0000000
--- a/lib/sqfs/util.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * util.h
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#ifndef SQFS_UTIL_H
-#define SQFS_UTIL_H
-
-#include "config.h"
-#include "sqfs/predef.h"
-#include "compat.h"
-
-#include <stddef.h>
-
-/*
- Helper for allocating data structures with flexible array members.
-
- 'base_size' is the size of the struct itself, 'item_size' the size of a
- single array element and 'nmemb' the number of elements.
-
- Iternally checks for arithmetic overflows when allocating the combined thing.
- */
-SQFS_INTERNAL
-void *alloc_flex(size_t base_size, size_t item_size, size_t nmemb);
-
-/* Basically the same as calloc, but *ALWAYS* does overflow checking */
-SQFS_INTERNAL
-void *alloc_array(size_t item_size, size_t nmemb);
-
-#endif /* SQFS_UTIL_H */
diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am
new file mode 100644
index 0000000..f5a5680
--- /dev/null
+++ b/lib/util/Makemodule.am
@@ -0,0 +1,6 @@
+libutil_a_SOURCES = include/util.h include/str_table.h
+libutil_a_SOURCES += lib/util/str_table.c lib/util/alloc.c
+libutil_a_CFLAGS = $(AM_CFLAGS)
+libutil_a_CPPFLAGS = $(AM_CPPFLAGS)
+
+noinst_LIBRARIES += libutil.a
diff --git a/lib/sqfs/alloc.c b/lib/util/alloc.c
index e8305d8..e8305d8 100644
--- a/lib/sqfs/alloc.c
+++ b/lib/util/alloc.c
diff --git a/lib/sqfs/str_table.c b/lib/util/str_table.c
index c0a364f..c0a364f 100644
--- a/lib/sqfs/str_table.c
+++ b/lib/util/str_table.c