libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 920e683212aae3d4996e8e7ad38801df8cc67141
parent ad4831cd56e71b305d5ecfe96bac8c8319f3dc11
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 11 Nov 2026 21:34:24 +0100

port: build and pass the test suite on macOS, FreeBSD and NetBSD

Darwin defines ntohll() itself, refuses to ftruncate() an existing shm
object and has an iconv that AM_ICONV wrongly rejects; NetBSD needs
libpthread loaded at startup for the GStreamer plugins, and FreeBSD
calls the tidy library libtidy5.

Assisted by LLM

Diffstat:
Mconfigure.ac | 14+++++++++++++-
Msrc/main/extractor_ipc_gnu.c | 30+++++++++++++++++++++---------
Msrc/plugins/Makefile.am | 10++++++++--
Msrc/plugins/qt_extractor.c | 8++++----
4 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -96,7 +96,11 @@ AS_CASE(["$target_os"], ], [netbsd*],[ AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system]) - AC_CHECK_LIB(c_r, pthread_create) + # NetBSD's libpthread only works if it is loaded at program start; + # if it arrives later with a plugin's dependencies (GStreamer/GLib), + # pthread_create() fails in the plugin process. Linking it into + # libextractor makes every application load it in time. + AC_CHECK_LIB(pthread, pthread_create) AM_CONDITIONAL(HAVE_GNU_LD, true) AM_CONDITIONAL(SOMEBSD, true) AM_CONDITIONAL(WINDOWS, false) @@ -186,6 +190,14 @@ AS_CASE(["$target_os"], ] ) +# Since macOS 14.4 the system iconv() transliterates instead of failing +# when a character has no equivalent in the target charset, and AM_ICONV +# therefore declares it "not working". We only ever convert *into* +# UTF-8 (or from UTF-8 into the locale's charset for display), where +# that cannot lose information, so the system iconv is fine for us; +# without it all non-UTF-8 meta data would be dropped. +AS_CASE(["$host_os"], + [darwin*],[: ${am_cv_func_iconv_works=yes}]) AM_ICONV PKG_PROG_PKG_CONFIG() diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c @@ -134,6 +134,7 @@ struct EXTRACTOR_SharedMemory * EXTRACTOR_IPC_shared_memory_create_ (size_t size) { struct EXTRACTOR_SharedMemory *shm; + unsigned int attempts = 0; if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) { @@ -146,15 +147,26 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size) system path: NetBSD keeps POSIX shared memory in a tmpfs of its own on /var/shm and rejects any name with an embedded slash with EINVAL, so prefixing a directory such as /tmp made every call to - shm_open() fail there. */ - snprintf (shm->shm_name, - MAX_SHM_NAME, - "/LE-%u-%u", - getpid (), - (unsigned int) random ()); - if (-1 == (shm->shm_id = shm_open (shm->shm_name, - O_RDWR | O_CREAT, - S_IRUSR | S_IWUSR))) + shm_open() fail there. + O_EXCL: an object of the same name may be left over from a process + that died before it could shm_unlink() it. Never reuse it: Darwin + refuses to ftruncate() an object that already has a size, which + would make every extraction of this process fail. */ + do + { + snprintf (shm->shm_name, + MAX_SHM_NAME, + "/LE-%u-%u", + getpid (), + (unsigned int) random ()); + shm->shm_id = shm_open (shm->shm_name, + O_RDWR | O_CREAT | O_EXCL, + S_IRUSR | S_IWUSR); + } + while ( (-1 == shm->shm_id) && + (EEXIST == errno) && + (++attempts < 16) ); + if (-1 == shm->shm_id) { LOG_STRERROR_FILE ("shm_open", shm->shm_name); diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -382,8 +382,14 @@ noinst_LTLIBRARIES = \ libtest_la_SOURCES = \ test_lib.c test_lib.h +# libextractor_common is not used by the tests themselves, but listing +# it makes libtool put its build directory on the library search path +# of the uninstalled test programs. On Darwin the plugins that need it +# refer to it by its *installed* name, so "make check" before "make +# install" could not load them otherwise. libtest_la_LIBADD = \ - $(top_builddir)/src/main/libextractor.la $(XLIB) + $(top_builddir)/src/main/libextractor.la \ + $(top_builddir)/src/common/libextractor_common.la $(XLIB) @@ -797,7 +803,7 @@ libextractor_html_la_CFLAGS = \ libextractor_html_la_LDFLAGS = \ $(PLUGINFLAGS) libextractor_html_la_LIBADD = \ - -ltidy -lmagic $(LTLIBICONV) $(XLIB) + $(TIDY_LIBS) -lmagic $(LTLIBICONV) $(XLIB) test_html_SOURCES = \ test_html.c diff --git a/src/plugins/qt_extractor.c b/src/plugins/qt_extractor.c @@ -506,7 +506,7 @@ LE_NETWORK_STRUCT_END static uint64_t -ntohll (uint64_t n) +qt_ntohll (uint64_t n) { #if __BYTE_ORDER == __BIG_ENDIAN return n; @@ -546,7 +546,7 @@ read_be64 (const void *p) uint64_t v; memcpy (&v, p, sizeof (v)); - return ntohll (v); + return qt_ntohll (v); } @@ -574,7 +574,7 @@ checkAtomValid (const char *buffer, (pos + sizeof (struct LongAtom) < pos) ) return false; latom = (const struct LongAtom *) &buffer[pos]; - atomSize = ntohll (latom->size); + atomSize = qt_ntohll (latom->size); if ((atomSize < sizeof (struct LongAtom)) || (atomSize + pos > size) || (atomSize + pos < atomSize)) return false; @@ -603,7 +603,7 @@ getAtomSize (const char *buf) if (ntohl (atom->size) == 1) { latom = (const struct LongAtom *) buf; - return ntohll (latom->size); + return qt_ntohll (latom->size); } return ntohl (atom->size); }