]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libarchive-util: several cleanups
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 8 Nov 2025 23:44:25 +0000 (08:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Nov 2025 09:09:31 +0000 (18:09 +0900)
- use loop for checking existence of functions,
- rename HAVE_LIBARCHIVE_XYZ -> HAVE_ARCHIVE_XYZ to make them match with
  the function name,
- do not conditionally include user-util.h in libarchive-util.h,
- sort library function symbols.

meson.build
src/shared/libarchive-util.c
src/shared/libarchive-util.h

index ef1b74b1633fe6c91bcc785d495b479eb72c2dfb..c289d7f53a6a4c23390bc56a86fdfcf2bea21a00 100644 (file)
@@ -1427,10 +1427,16 @@ libarchive = dependency('libarchive',
                         required : get_option('libarchive'))
 libarchive_cflags = libarchive.partial_dependency(includes: true, compile_args: true)
 conf.set10('HAVE_LIBARCHIVE', libarchive.found())
-conf.set10('HAVE_LIBARCHIVE_UID_IS_SET',
-           libarchive.found() and cc.has_function('archive_entry_uid_is_set', dependencies : libarchive))
-conf.set10('HAVE_LIBARCHIVE_HARDLINK_IS_SET',
-           libarchive.found() and cc.has_function('archive_entry_hardlink_is_set', dependencies : libarchive))
+
+foreach ident : [
+                'archive_entry_gid_is_set',      # since 3.7.3
+                'archive_entry_uid_is_set',      # since 3.7.3
+                'archive_entry_hardlink_is_set', # since 3.7.5
+        ]
+
+        have = libarchive.found() and cc.has_function(ident, dependencies : libarchive)
+        conf.set10('HAVE_' + ident.to_upper(), have)
+endforeach
 
 libxkbcommon = dependency('xkbcommon',
                           version : '>= 0.3.0',
index 09f036895ce2cceec944a2bb796fc66e45fc0c23..35083a266f1110edf9d66eb0fcca41a75f5724d4 100644 (file)
@@ -3,6 +3,7 @@
 #include <syslog.h>
 
 #include "libarchive-util.h"
+#include "user-util.h"
 
 #if HAVE_LIBARCHIVE
 static void *libarchive_dl = NULL;
@@ -14,11 +15,15 @@ DLSYM_PROTOTYPE(archive_entry_fflags) = NULL;
 DLSYM_PROTOTYPE(archive_entry_filetype) = NULL;
 DLSYM_PROTOTYPE(archive_entry_free) = NULL;
 DLSYM_PROTOTYPE(archive_entry_gid) = NULL;
-#if HAVE_LIBARCHIVE_UID_IS_SET
+#if HAVE_ARCHIVE_ENTRY_GID_IS_SET
 DLSYM_PROTOTYPE(archive_entry_gid_is_set) = NULL;
+#else
+int sym_archive_entry_gid_is_set(struct archive_entry *e) {
+        return gid_is_valid(sym_archive_entry_gid(e));
+}
 #endif
 DLSYM_PROTOTYPE(archive_entry_hardlink) = NULL;
-#if HAVE_LIBARCHIVE_HARDLINK_IS_SET
+#if HAVE_ARCHIVE_ENTRY_HARDLINK_IS_SET
 DLSYM_PROTOTYPE(archive_entry_hardlink_is_set) = NULL;
 #endif
 DLSYM_PROTOTYPE(archive_entry_mode) = NULL;
@@ -45,8 +50,12 @@ DLSYM_PROTOTYPE(archive_entry_set_uid) = NULL;
 DLSYM_PROTOTYPE(archive_entry_sparse_add_entry) = NULL;
 DLSYM_PROTOTYPE(archive_entry_symlink) = NULL;
 DLSYM_PROTOTYPE(archive_entry_uid) = NULL;
-#if HAVE_LIBARCHIVE_UID_IS_SET
+#if HAVE_ARCHIVE_ENTRY_UID_IS_SET
 DLSYM_PROTOTYPE(archive_entry_uid_is_set) = NULL;
+#else
+int sym_archive_entry_uid_is_set(struct archive_entry *e) {
+        return uid_is_valid(sym_archive_entry_uid(e));
+}
 #endif
 DLSYM_PROTOTYPE(archive_entry_xattr_add_entry) = NULL;
 DLSYM_PROTOTYPE(archive_entry_xattr_next) = NULL;
@@ -86,11 +95,11 @@ int dlopen_libarchive(void) {
                         DLSYM_ARG(archive_entry_filetype),
                         DLSYM_ARG(archive_entry_free),
                         DLSYM_ARG(archive_entry_gid),
-#if HAVE_LIBARCHIVE_UID_IS_SET
+#if HAVE_ARCHIVE_ENTRY_GID_IS_SET
                         DLSYM_ARG(archive_entry_gid_is_set),
 #endif
                         DLSYM_ARG(archive_entry_hardlink),
-#if HAVE_LIBARCHIVE_HARDLINK_IS_SET
+#if HAVE_ARCHIVE_ENTRY_HARDLINK_IS_SET
                         DLSYM_ARG(archive_entry_hardlink_is_set),
 #endif
                         DLSYM_ARG(archive_entry_mode),
@@ -117,7 +126,7 @@ int dlopen_libarchive(void) {
                         DLSYM_ARG(archive_entry_sparse_add_entry),
                         DLSYM_ARG(archive_entry_symlink),
                         DLSYM_ARG(archive_entry_uid),
-#if HAVE_LIBARCHIVE_UID_IS_SET
+#if HAVE_ARCHIVE_ENTRY_UID_IS_SET
                         DLSYM_ARG(archive_entry_uid_is_set),
 #endif
                         DLSYM_ARG(archive_entry_xattr_add_entry),
index 615cd1ec810ce0fb72a61f7ae23656291aaab193..db1c31d2239f742f51b67e2cc76f5afe7d17fb18 100644 (file)
@@ -16,7 +16,19 @@ extern DLSYM_PROTOTYPE(archive_entry_fflags);
 extern DLSYM_PROTOTYPE(archive_entry_filetype);
 extern DLSYM_PROTOTYPE(archive_entry_free);
 extern DLSYM_PROTOTYPE(archive_entry_gid);
+#if HAVE_ARCHIVE_ENTRY_GID_IS_SET
+extern DLSYM_PROTOTYPE(archive_entry_gid_is_set);
+#else
+int sym_archive_entry_gid_is_set(struct archive_entry *e);
+#endif
 extern DLSYM_PROTOTYPE(archive_entry_hardlink);
+#if HAVE_ARCHIVE_ENTRY_HARDLINK_IS_SET
+extern DLSYM_PROTOTYPE(archive_entry_hardlink_is_set);
+#else
+static inline int sym_archive_entry_hardlink_is_set(struct archive_entry *e) {
+        return !!sym_archive_entry_hardlink(e);
+}
+#endif
 extern DLSYM_PROTOTYPE(archive_entry_mode);
 extern DLSYM_PROTOTYPE(archive_entry_mtime);
 extern DLSYM_PROTOTYPE(archive_entry_mtime_is_set);
@@ -41,6 +53,11 @@ extern DLSYM_PROTOTYPE(archive_entry_set_uid);
 extern DLSYM_PROTOTYPE(archive_entry_sparse_add_entry);
 extern DLSYM_PROTOTYPE(archive_entry_symlink);
 extern DLSYM_PROTOTYPE(archive_entry_uid);
+#if HAVE_ARCHIVE_ENTRY_UID_IS_SET
+extern DLSYM_PROTOTYPE(archive_entry_uid_is_set);
+#else
+int sym_archive_entry_uid_is_set(struct archive_entry *e);
+#endif
 extern DLSYM_PROTOTYPE(archive_entry_xattr_add_entry);
 extern DLSYM_PROTOTYPE(archive_entry_xattr_next);
 extern DLSYM_PROTOTYPE(archive_entry_xattr_reset);
@@ -62,27 +79,6 @@ extern DLSYM_PROTOTYPE(archive_write_open_fd);
 extern DLSYM_PROTOTYPE(archive_write_set_format_filter_by_ext);
 extern DLSYM_PROTOTYPE(archive_write_set_format_pax);
 
-#if HAVE_LIBARCHIVE_UID_IS_SET
-extern DLSYM_PROTOTYPE(archive_entry_gid_is_set);
-extern DLSYM_PROTOTYPE(archive_entry_uid_is_set);
-#else
-#include "user-util.h"
-static inline int sym_archive_entry_gid_is_set(struct archive_entry *e) {
-        return gid_is_valid(sym_archive_entry_gid(e));
-}
-static inline int sym_archive_entry_uid_is_set(struct archive_entry *e) {
-        return uid_is_valid(sym_archive_entry_uid(e));
-}
-#endif
-
-#if HAVE_LIBARCHIVE_HARDLINK_IS_SET
-extern DLSYM_PROTOTYPE(archive_entry_hardlink_is_set);
-#else
-static inline int sym_archive_entry_hardlink_is_set(struct archive_entry *e) {
-        return !!sym_archive_entry_hardlink(e);
-}
-#endif
-
 int dlopen_libarchive(void);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive_entry*, sym_archive_entry_free, archive_entry_freep, NULL);