From: Daan De Meyer Date: Mon, 5 May 2025 12:15:47 +0000 (+0200) Subject: iovec-util: Reduce transitive includes X-Git-Tag: v258-rc1~672^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e53d4f343d7d3f6dea47c81e19952a74154fb4e8;p=thirdparty%2Fsystemd.git iovec-util: Reduce transitive includes --- diff --git a/src/analyze/analyze-pcrs.c b/src/analyze/analyze-pcrs.c index 23f8f0773d8..f00f4c95a12 100644 --- a/src/analyze/analyze-pcrs.c +++ b/src/analyze/analyze-pcrs.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "analyze.h" #include "analyze-pcrs.h" #include "fileio.h" diff --git a/src/analyze/analyze-srk.c b/src/analyze/analyze-srk.c index adbc51316af..973f92e64cf 100644 --- a/src/analyze/analyze-srk.c +++ b/src/analyze/analyze-srk.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "analyze.h" #include "analyze-srk.h" #include "fileio.h" diff --git a/src/basic/iovec-util.c b/src/basic/iovec-util.c index 76f7f5f29eb..ec8af57e642 100644 --- a/src/basic/iovec-util.c +++ b/src/basic/iovec-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "iovec-util.h" #include "string-util.h" @@ -51,6 +52,20 @@ bool iovec_increment(struct iovec *iovec, size_t n, size_t k) { return true; } +struct iovec* iovec_make_string(struct iovec *iovec, const char *s) { + assert(iovec); + + *iovec = IOVEC_MAKE(s, strlen_ptr(s)); + return iovec; +} + +void iovec_done_erase(struct iovec *iovec) { + assert(iovec); + + iovec->iov_base = erase_and_free(iovec->iov_base); + iovec->iov_len = 0; +} + char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) { char *x; @@ -83,6 +98,33 @@ void iovec_array_free(struct iovec *iovec, size_t n_iovec) { free(iovec); } +int iovec_memcmp(const struct iovec *a, const struct iovec *b) { + + if (a == b) + return 0; + + return memcmp_nn(a ? a->iov_base : NULL, + a ? a->iov_len : 0, + b ? b->iov_base : NULL, + b ? b->iov_len : 0); +} + +struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret) { + assert(ret); + + if (!iovec_is_set(source)) + *ret = (struct iovec) {}; + else { + void *p = memdup(source->iov_base, source->iov_len); + if (!p) + return NULL; + + *ret = IOVEC_MAKE(p, source->iov_len); + } + + return ret; +} + struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append) { assert(iovec_is_valid(iovec)); diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index ace20098c88..d194195e745 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -5,7 +5,6 @@ #include #include -#include "alloc-util.h" #include "iovec-util-fundamental.h" #include "macro.h" @@ -16,12 +15,7 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n) _nonnull_if_nonzero bool iovec_increment(struct iovec *iovec, size_t n, size_t k) _nonnull_if_nonzero_(1, 2); -static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s) { - assert(iovec); - /* We don't use strlen_ptr() here, because we don't want to include string-util.h for now */ - *iovec = IOVEC_MAKE(s, s ? strlen(s) : 0); - return iovec; -} +struct iovec* iovec_make_string(struct iovec *iovec, const char *s); #define IOVEC_MAKE_STRING(s) \ *iovec_make_string(&(struct iovec) {}, s) @@ -32,43 +26,15 @@ static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s .iov_len = STRLEN(s), \ } -static inline void iovec_done_erase(struct iovec *iovec) { - assert(iovec); - - iovec->iov_base = erase_and_free(iovec->iov_base); - iovec->iov_len = 0; -} +void iovec_done_erase(struct iovec *iovec); char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value); char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value); void iovec_array_free(struct iovec *iovec, size_t n_iovec) _nonnull_if_nonzero_(1, 2); -static inline int iovec_memcmp(const struct iovec *a, const struct iovec *b) { - - if (a == b) - return 0; - - return memcmp_nn(a ? a->iov_base : NULL, - a ? a->iov_len : 0, - b ? b->iov_base : NULL, - b ? b->iov_len : 0); -} - -static inline struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret) { - assert(ret); - - if (!iovec_is_set(source)) - *ret = (struct iovec) {}; - else { - void *p = memdup(source->iov_base, source->iov_len); - if (!p) - return NULL; - - *ret = IOVEC_MAKE(p, source->iov_len); - } +int iovec_memcmp(const struct iovec *a, const struct iovec *b) _pure_; - return ret; -} +struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret); struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append); diff --git a/src/basic/log-context.c b/src/basic/log-context.c index 8ab468ed9d8..fd40c055a4c 100644 --- a/src/basic/log-context.c +++ b/src/basic/log-context.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "env-util.h" #include "iovec-util.h" #include "log.h" diff --git a/src/bootctl/bootctl-install.c b/src/bootctl/bootctl-install.c index 20c3336009f..8927464c465 100644 --- a/src/bootctl/bootctl-install.c +++ b/src/bootctl/bootctl-install.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "bootctl.h" #include "bootctl-install.h" #include "bootctl-random-seed.h" diff --git a/src/bootctl/bootctl-set-efivar.c b/src/bootctl/bootctl-set-efivar.c index 75cae290977..d53458c4910 100644 --- a/src/bootctl/bootctl-set-efivar.c +++ b/src/bootctl/bootctl-set-efivar.c @@ -3,6 +3,7 @@ #include #include +#include "alloc-util.h" #include "bootctl.h" #include "bootctl-set-efivar.h" #include "efi-loader.h" diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index 6021c1a5aed..38fe5273bec 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -4,6 +4,7 @@ #include #include +#include "alloc-util.h" #include "bootctl.h" #include "bootctl-status.h" #include "bootctl-util.h" diff --git a/src/bootctl/bootctl-util.c b/src/bootctl/bootctl-util.c index bc0b0d7c9c9..41eadbdf1b5 100644 --- a/src/bootctl/bootctl-util.c +++ b/src/bootctl/bootctl-util.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "bootctl.h" #include "bootctl-util.h" #include "errno-util.h" diff --git a/src/cryptsetup/cryptsetup-keyfile.c b/src/cryptsetup/cryptsetup-keyfile.c index d513f5d0a98..fb80cecd346 100644 --- a/src/cryptsetup/cryptsetup-keyfile.c +++ b/src/cryptsetup/cryptsetup-keyfile.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "cryptsetup-keyfile.h" #include "fileio.h" #include "log.h" diff --git a/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c b/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c index 9e94c974c9b..787d35b2162 100644 --- a/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c +++ b/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c @@ -4,6 +4,7 @@ #include #include +#include "alloc-util.h" #include "cryptsetup-token.h" #include "cryptsetup-token-util.h" #include "hexdecoct.h" diff --git a/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c b/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c index e067950da70..967b26df4d7 100644 --- a/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c +++ b/src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-tpm2.c @@ -3,6 +3,7 @@ #include #include +#include "alloc-util.h" #include "cryptsetup-token.h" #include "cryptsetup-token-util.h" #include "hexdecoct.h" diff --git a/src/cryptsetup/cryptsetup-tokens/luks2-fido2.c b/src/cryptsetup/cryptsetup-tokens/luks2-fido2.c index 67714af690d..18b0e4f37f9 100644 --- a/src/cryptsetup/cryptsetup-tokens/luks2-fido2.c +++ b/src/cryptsetup/cryptsetup-tokens/luks2-fido2.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "cryptsetup-token-util.h" #include "hexdecoct.h" #include "json-util.h" diff --git a/src/home/homectl-fido2.c b/src/home/homectl-fido2.c index 772edcf95b0..1b89e588906 100644 --- a/src/home/homectl-fido2.c +++ b/src/home/homectl-fido2.c @@ -4,6 +4,7 @@ #include #endif +#include "alloc-util.h" #include "ask-password-api.h" #include "errno-util.h" #include "fido2-util.h" diff --git a/src/home/user-record-sign.c b/src/home/user-record-sign.c index 2cdd20efe57..1f0bc88e417 100644 --- a/src/home/user-record-sign.c +++ b/src/home/user-record-sign.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "json-util.h" diff --git a/src/libsystemd-network/icmp6-packet.c b/src/libsystemd-network/icmp6-packet.c index 02865a40c25..fe531ba14aa 100644 --- a/src/libsystemd-network/icmp6-packet.c +++ b/src/libsystemd-network/icmp6-packet.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "icmp6-packet.h" #include "icmp6-util.h" #include "in-addr-util.h" diff --git a/src/libsystemd-network/ndisc-option.c b/src/libsystemd-network/ndisc-option.c index daa7aba5eab..1d4be8e2dd2 100644 --- a/src/libsystemd-network/ndisc-option.c +++ b/src/libsystemd-network/ndisc-option.c @@ -3,6 +3,7 @@ #include #include +#include "alloc-util.h" #include "dns-domain.h" #include "dns-resolver-internal.h" #include "ether-addr-util.h" diff --git a/src/libsystemd-network/sd-dhcp-server-lease.c b/src/libsystemd-network/sd-dhcp-server-lease.c index 32706bf842b..8b4c1012b5c 100644 --- a/src/libsystemd-network/sd-dhcp-server-lease.c +++ b/src/libsystemd-network/sd-dhcp-server-lease.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "dhcp-server-lease-internal.h" #include "fd-util.h" #include "fs-util.h" diff --git a/src/libsystemd/sd-netlink/netlink-message-nfnl.c b/src/libsystemd/sd-netlink/netlink-message-nfnl.c index 66049d3106d..72bcdde1bdd 100644 --- a/src/libsystemd/sd-netlink/netlink-message-nfnl.c +++ b/src/libsystemd/sd-netlink/netlink-message-nfnl.c @@ -7,6 +7,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "iovec-util.h" #include "log.h" #include "netlink-internal.h" diff --git a/src/network/networkd-serialize.c b/src/network/networkd-serialize.c index 78c13b81c15..8e29bc518a1 100644 --- a/src/network/networkd-serialize.c +++ b/src/network/networkd-serialize.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "af-list.h" +#include "alloc-util.h" #include "daemon-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/resolve/resolved-dnstls.c b/src/resolve/resolved-dnstls.c index c56f62e1e33..a03919cfedd 100644 --- a/src/resolve/resolved-dnstls.c +++ b/src/resolve/resolved-dnstls.c @@ -8,6 +8,7 @@ #include #include +#include "alloc-util.h" #include "io-util.h" #include "openssl-util.h" #include "resolved-dns-server.h" diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 15021ae2510..e5ca2ccbb3c 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -3,6 +3,7 @@ #include #include +#include "alloc-util.h" #include "bootspec.h" #include "bootspec-fundamental.h" #include "chase.h" diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 67707dee1ec..6eca4aa88c5 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -10,6 +10,7 @@ #include "sd-json.h" #include "sd-varlink.h" +#include "alloc-util.h" #include "blockdev-util.h" #include "capability-util.h" #include "chattr-util.h" diff --git a/src/shared/fido2-util.c b/src/shared/fido2-util.c index 8c893d6b23c..b0ec7ec4100 100644 --- a/src/shared/fido2-util.c +++ b/src/shared/fido2-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "fido2-util.h" #include "fileio.h" #include "libfido2-util.h" diff --git a/src/shared/kernel-image.c b/src/shared/kernel-image.c index 090281de5e1..3e31ec92ef2 100644 --- a/src/shared/kernel-image.c +++ b/src/shared/kernel-image.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "env-file.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/shared/openssl-util.h b/src/shared/openssl-util.h index 240d6f26e63..a32e19d37d7 100644 --- a/src/shared/openssl-util.h +++ b/src/shared/openssl-util.h @@ -3,7 +3,7 @@ #include "ask-password-api.h" #include "iovec-util.h" -#include "macro.h" +#include "memory-util.h" #include "sha256.h" typedef enum CertificateSourceType { diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index 04c6d691c66..1104e1e33a2 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -2,6 +2,7 @@ #include +#include "alloc-util.h" #include "ask-password-api.h" #include "dlfcn-util.h" #include "env-util.h"