Debian Codegraph @

src/shared/libarchive-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-dlopen.h"
5
6 #include "shared-forward.h"
7
8 #if HAVE_LIBARCHIVE
9 #include <archive.h> /* IWYU pragma: export */
10 #include <archive_entry.h> /* IWYU pragma: export */
11
12 #include "dlfcn-util.h"
13
14 /* Newer symbols that might not be in the header we build against. Always redeclare so DLSYM_PROTOTYPE's
15 * typeof() resolves; suppress the warning when newer libarchive already declared them. */
16 DISABLE_WARNING_REDUNDANT_DECLS;
17 /* NOLINTBEGIN(readability-redundant-declaration) */
18 extern int archive_entry_gid_is_set(struct archive_entry *e);
19 extern int archive_entry_hardlink_is_set(struct archive_entry *e);
20 extern int archive_entry_uid_is_set(struct archive_entry *e);
21 /* NOLINTEND(readability-redundant-declaration) */
22 REENABLE_WARNING;
23
24 extern DLSYM_PROTOTYPE(archive_entry_acl_add_entry);
25 extern DLSYM_PROTOTYPE(archive_entry_acl_next);
26 extern DLSYM_PROTOTYPE(archive_entry_acl_reset);
27 extern DLSYM_PROTOTYPE(archive_entry_fflags);
28 extern DLSYM_PROTOTYPE(archive_entry_filetype);
29 extern DLSYM_PROTOTYPE(archive_entry_free);
30 extern DLSYM_PROTOTYPE(archive_entry_gid);
31 extern DLSYM_PROTOTYPE(archive_entry_gid_is_set);
32 extern DLSYM_PROTOTYPE(archive_entry_hardlink);
33 extern DLSYM_PROTOTYPE(archive_entry_hardlink_is_set);
34 extern DLSYM_PROTOTYPE(archive_entry_mode);
35 extern DLSYM_PROTOTYPE(archive_entry_mtime);
36 extern DLSYM_PROTOTYPE(archive_entry_mtime_is_set);
37 extern DLSYM_PROTOTYPE(archive_entry_mtime_nsec);
38 extern DLSYM_PROTOTYPE(archive_entry_new);
39 extern DLSYM_PROTOTYPE(archive_entry_pathname);
40 extern DLSYM_PROTOTYPE(archive_entry_rdevmajor);
41 extern DLSYM_PROTOTYPE(archive_entry_rdevminor);
42 extern DLSYM_PROTOTYPE(archive_entry_set_ctime);
43 extern DLSYM_PROTOTYPE(archive_entry_set_fflags);
44 extern DLSYM_PROTOTYPE(archive_entry_set_filetype);
45 extern DLSYM_PROTOTYPE(archive_entry_set_gid);
46 extern DLSYM_PROTOTYPE(archive_entry_set_hardlink);
47 extern DLSYM_PROTOTYPE(archive_entry_set_mtime);
48 extern DLSYM_PROTOTYPE(archive_entry_set_pathname);
49 extern DLSYM_PROTOTYPE(archive_entry_set_perm);
50 extern DLSYM_PROTOTYPE(archive_entry_set_rdevmajor);
51 extern DLSYM_PROTOTYPE(archive_entry_set_rdevminor);
52 extern DLSYM_PROTOTYPE(archive_entry_set_size);
53 extern DLSYM_PROTOTYPE(archive_entry_set_symlink);
54 extern DLSYM_PROTOTYPE(archive_entry_set_uid);
55 extern DLSYM_PROTOTYPE(archive_entry_sparse_add_entry);
56 extern DLSYM_PROTOTYPE(archive_entry_symlink);
57 extern DLSYM_PROTOTYPE(archive_entry_uid);
58 extern DLSYM_PROTOTYPE(archive_entry_uid_is_set);
59 extern DLSYM_PROTOTYPE(archive_entry_xattr_add_entry);
60 extern DLSYM_PROTOTYPE(archive_entry_xattr_next);
61 extern DLSYM_PROTOTYPE(archive_entry_xattr_reset);
62 extern DLSYM_PROTOTYPE(archive_error_string);
63 extern DLSYM_PROTOTYPE(archive_read_data_into_fd);
64 extern DLSYM_PROTOTYPE(archive_read_free);
65 extern DLSYM_PROTOTYPE(archive_read_new);
66 extern DLSYM_PROTOTYPE(archive_read_next_header);
67 extern DLSYM_PROTOTYPE(archive_read_open_fd);
68 extern DLSYM_PROTOTYPE(archive_read_support_format_cpio);
69 extern DLSYM_PROTOTYPE(archive_read_support_format_tar);
70 extern DLSYM_PROTOTYPE(archive_write_close);
71 extern DLSYM_PROTOTYPE(archive_write_data);
72 extern DLSYM_PROTOTYPE(archive_write_free);
73 extern DLSYM_PROTOTYPE(archive_write_header);
74 extern DLSYM_PROTOTYPE(archive_write_new);
75 extern DLSYM_PROTOTYPE(archive_write_open_FILE);
76 extern DLSYM_PROTOTYPE(archive_write_open_fd);
77 extern DLSYM_PROTOTYPE(archive_write_set_format_filter_by_ext);
78 extern DLSYM_PROTOTYPE(archive_write_set_format_pax);
79
80 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive_entry*, sym_archive_entry_free, archive_entry_freep, NULL);
81 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_write_free, archive_write_freep, NULL);
82 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_read_free, archive_read_freep, NULL);
83
84 #define LIBARCHIVE_NOTE(priority) \
85 SD_ELF_NOTE_DLOPEN("archive", \
86 "Support for decompressing archive files", \
87 priority, \
88 "libarchive.so.13")
89
90 #define DLOPEN_LIBARCHIVE(log_level, priority) \
91 ({ \
92 LIBARCHIVE_NOTE(priority); \
93 dlopen_libarchive(log_level); \
94 })
95
96 #else
97 #define DLOPEN_LIBARCHIVE(log_level, priority) dlopen_libarchive(log_level)
98 #endif
99
100 int dlopen_libarchive(int log_level);