diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-03-14 13:14:33 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-03-14 13:25:52 +0100 |
commit | d8b4d14df4a8271504bb4c1e3c11f17684f09a14 (patch) | |
tree | 6c3dbf914f29467bdba4b43718ea96f7abab4478 | |
parent | util: move some raw memory functions from string-util.h → memory-util.h (diff) | |
download | systemd-d8b4d14df4a8271504bb4c1e3c11f17684f09a14.tar.xz systemd-d8b4d14df4a8271504bb4c1e3c11f17684f09a14.zip |
util: split out nulstr related stuff to nulstr-util.[ch]
40 files changed, 70 insertions, 40 deletions
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index 9e4cac6e29..a978ed6da8 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -13,6 +13,7 @@ #include "locale-util.h" #include "macro.h" #include "missing.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index f838daada8..299c5917bc 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -29,6 +29,7 @@ #include "locale-util.h" #include "log.h" #include "main-func.h" +#include "nulstr-util.h" #include "pager.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/basic/kbd-util.c b/src/basic/kbd-util.c index f178b5dfea..17d4022dbe 100644 --- a/src/basic/kbd-util.c +++ b/src/basic/kbd-util.c @@ -4,6 +4,7 @@ #include "kbd-util.h" #include "log.h" +#include "nulstr-util.h" #include "path-util.h" #include "set.h" #include "string-util.h" diff --git a/src/basic/meson.build b/src/basic/meson.build index 82b245c90b..91e0df3d2f 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -137,6 +137,8 @@ basic_sources = files(''' namespace-util.c namespace-util.h nss-util.h + nulstr-util.c + nulstr-util.h ordered-set.c ordered-set.h parse-util.c diff --git a/src/basic/nulstr-util.c b/src/basic/nulstr-util.c new file mode 100644 index 0000000000..b12d020232 --- /dev/null +++ b/src/basic/nulstr-util.c @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "nulstr-util.h" +#include "string-util.h" + +bool nulstr_contains(const char *nulstr, const char *needle) { + const char *i; + + if (!nulstr) + return false; + + NULSTR_FOREACH(i, nulstr) + if (streq(i, needle)) + return true; + + return false; +} diff --git a/src/basic/nulstr-util.h b/src/basic/nulstr-util.h new file mode 100644 index 0000000000..436b271f3c --- /dev/null +++ b/src/basic/nulstr-util.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include <stdbool.h> +#include <string.h> + +#define NULSTR_FOREACH(i, l) \ + for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1) + +#define NULSTR_FOREACH_PAIR(i, j, l) \ + for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i)) + +bool nulstr_contains(const char *nulstr, const char *needle); diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 1fa813b747..55cb140d87 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -21,6 +21,7 @@ #include "log.h" #include "macro.h" #include "missing.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "stat-util.h" diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 49c2679e98..5001a2be3a 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -676,19 +676,6 @@ char *cellescape(char *buf, size_t len, const char *s) { return buf; } -bool nulstr_contains(const char *nulstr, const char *needle) { - const char *i; - - if (!nulstr) - return false; - - NULSTR_FOREACH(i, nulstr) - if (streq(i, needle)) - return true; - - return false; -} - char* strshorten(char *s, size_t l) { assert(s); diff --git a/src/basic/string-util.h b/src/basic/string-util.h index b5328e0e8a..b0909dddca 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -165,8 +165,6 @@ char *cellescape(char *buf, size_t len, const char *s); /* This limit is arbitrary, enough to give some idea what the string contains */ #define CELLESCAPE_DEFAULT_LENGTH 64 -bool nulstr_contains(const char *nulstr, const char *needle); - char* strshorten(char *s, size_t l); char *strreplace(const char *text, const char *old_string, const char *new_string); diff --git a/src/basic/strv.c b/src/basic/strv.c index 3700ce5b30..21c106149b 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -11,6 +11,7 @@ #include "escape.h" #include "extract-word.h" #include "fileio.h" +#include "nulstr-util.h" #include "sort-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/basic/util.h b/src/basic/util.h index 469f3eee4d..0d40db059a 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -43,12 +43,6 @@ static inline const char* enable_disable(bool b) { return b ? "enable" : "disable"; } -#define NULSTR_FOREACH(i, l) \ - for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1) - -#define NULSTR_FOREACH_PAIR(i, j, l) \ - for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i)) - extern int saved_argc; extern char **saved_argv; diff --git a/src/core/cgroup.c b/src/core/cgroup.c index ccf06173db..059bf29eb9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -5,15 +5,16 @@ #include "alloc-util.h" #include "blockdev-util.h" +#include "bpf-devices.h" #include "bpf-firewall.h" #include "btrfs-util.h" -#include "bpf-devices.h" #include "bus-error.h" #include "cgroup-util.h" #include "cgroup.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 805bdbca9b..2f62c7acb5 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -41,6 +41,7 @@ #include "log.h" #include "missing.h" #include "mountpoint-util.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 3ce6164b06..b97285e556 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -23,12 +23,12 @@ #include "mkdir.h" #include "mount-setup.h" #include "mountpoint-util.h" +#include "nulstr-util.h" #include "path-util.h" #include "set.h" #include "smack-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" #include "virt.h" typedef enum MountMode { diff --git a/src/core/namespace.c b/src/core/namespace.c index 582f6cb249..e6013c757e 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -23,6 +23,7 @@ #include "mountpoint-util.h" #include "namespace-util.h" #include "namespace.h" +#include "nulstr-util.h" #include "path-util.h" #include "selinux-util.h" #include "socket-util.h" diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a16ea1024b..87e0cefbab 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -16,12 +16,12 @@ #include "log.h" #include "main-func.h" #include "mount-util.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" +#include "pretty-print.h" #include "string-util.h" #include "strv.h" -#include "pretty-print.h" -#include "util.h" /* internal helper */ #define ANY_LUKS "LUKS" diff --git a/src/delta/delta.c b/src/delta/delta.c index 1ffbc6c571..c28a816d67 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -14,6 +14,7 @@ #include "locale-util.h" #include "log.h" #include "main-func.h" +#include "nulstr-util.h" #include "pager.h" #include "parse-util.h" #include "path-util.h" @@ -24,7 +25,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" static const char prefixes[] = "/etc\0" diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 7777450c35..058a71b109 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -19,6 +19,7 @@ #include "main-func.h" #include "missing_capability.h" #include "nscd-flush.h" +#include "nulstr-util.h" #include "os-util.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 9b813a14a0..42a5a09608 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -52,6 +52,7 @@ #include "logs-show.h" #include "memory-util.h" #include "mkdir.h" +#include "nulstr-util.h" #include "pager.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 0f996283cd..82e7d59fbb 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -32,6 +32,7 @@ #include "list.h" #include "lookup3.h" #include "missing.h" +#include "nulstr-util.h" #include "path-util.h" #include "process-util.h" #include "replace-var.h" diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 1838f5b7d9..1005997058 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -5,12 +5,12 @@ #include "env-util.h" #include "macro.h" #include "memory-util.h" +#include "nulstr-util.h" #include "parse-util.h" #include "process-util.h" #include "random-util.h" #include "string-util.h" #include "tests.h" -#include "util.h" typedef int (compress_t)(const void *src, uint64_t src_size, void *dst, size_t dst_alloc_size, size_t *dst_size); diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 6f17eeeee9..a0855001e3 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -16,6 +16,7 @@ #include "hashmap.h" #include "macro.h" #include "mkdir.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "set.h" @@ -25,7 +26,6 @@ #include "strxcpyx.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" int device_add_property(sd_device *device, const char *key, const char *value) { int r; diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index d8c37c3fd4..77531d9505 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -18,8 +18,8 @@ #include "hashmap.h" #include "hwdb-internal.h" #include "hwdb-util.h" +#include "nulstr-util.h" #include "string-util.h" -#include "util.h" struct sd_hwdb { unsigned n_ref; diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c index 64d18d916e..67f33612de 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -17,6 +17,7 @@ #include "locale-util.h" #include "macro.h" #include "mkdir.h" +#include "nulstr-util.h" #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index b24698469d..c8607bcec3 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -37,6 +37,7 @@ #include "macro.h" #include "main-func.h" #include "mkdir.h" +#include "nulstr-util.h" #include "pager.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index c6cc82b12f..05203057b6 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -74,6 +74,7 @@ #include "nspawn-settings.h" #include "nspawn-setuid.h" #include "nspawn-stub-pid1.h" +#include "nulstr-util.h" #include "os-util.h" #include "pager.h" #include "parse-util.h" diff --git a/src/portable/portable.c b/src/portable/portable.c index 9d0d21c115..44e6ca2d30 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -17,6 +17,7 @@ #include "loop-util.h" #include "machine-image.h" #include "mkdir.h" +#include "nulstr-util.h" #include "os-util.h" #include "path-lookup.h" #include "portable.h" diff --git a/src/resolve/resolved-dns-trust-anchor.c b/src/resolve/resolved-dns-trust-anchor.c index e5a27ca688..d25b5f9d95 100644 --- a/src/resolve/resolved-dns-trust-anchor.c +++ b/src/resolve/resolved-dns-trust-anchor.c @@ -9,6 +9,7 @@ #include "fd-util.h" #include "fileio.h" #include "hexdecoct.h" +#include "nulstr-util.h" #include "parse-util.h" #include "resolved-dns-dnssec.h" #include "resolved-dns-trust-anchor.h" diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 89d7a7d59b..52460cacad 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -13,10 +13,10 @@ #include "fd-util.h" #include "log.h" #include "macro.h" +#include "nulstr-util.h" #include "string-util.h" #include "umask-util.h" #include "user-util.h" -#include "util.h" typedef struct BaseFilesystem { const char *dir; diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index aa8283313f..2df09edaf5 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -19,6 +19,7 @@ #include "log.h" #include "macro.h" #include "missing.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index b545c2a1c0..12e80e4b98 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -8,10 +8,10 @@ #include "dev-setup.h" #include "label.h" #include "log.h" +#include "nulstr-util.h" #include "path-util.h" #include "umask-util.h" #include "user-util.h" -#include "util.h" int dev_setup(const char *prefix, uid_t uid, gid_t gid) { static const char symlinks[] = diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 201a515589..ce210bfd43 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -29,6 +29,7 @@ #include "missing.h" #include "mount-util.h" #include "mountpoint-util.h" +#include "nulstr-util.h" #include "os-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 6fd9866c00..118d591c09 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -11,11 +11,11 @@ #include "fstab-util.h" #include "macro.h" #include "mount-util.h" +#include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" int fstab_has_fstype(const char *fstype) { _cleanup_endmntent_ FILE *f = NULL; diff --git a/src/shared/import-util.c b/src/shared/import-util.c index bcd6c0c5ea..dad6c1c2fe 100644 --- a/src/shared/import-util.c +++ b/src/shared/import-util.c @@ -8,10 +8,10 @@ #include "import-util.h" #include "log.h" #include "macro.h" +#include "nulstr-util.h" #include "path-util.h" #include "string-table.h" #include "string-util.h" -#include "util.h" int import_url_last_component(const char *url, char **ret) { const char *e, *p; diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 3d61221056..c5a6f2d4ee 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -31,6 +31,7 @@ #include "machine-image.h" #include "macro.h" #include "mkdir.h" +#include "nulstr-util.h" #include "os-util.h" #include "path-util.h" #include "rm-rf.h" @@ -39,7 +40,6 @@ #include "strv.h" #include "time-util.h" #include "utf8.h" -#include "util.h" #include "xattr-util.h" static const char* const image_search_path[_IMAGE_CLASS_MAX] = { diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index 98a0066bae..54f9679e16 100644 --- a/src/shared/seccomp-util.c +++ b/src/shared/seccomp-util.c @@ -10,15 +10,15 @@ #include "af-list.h" #include "alloc-util.h" +#include "errno-list.h" #include "macro.h" #include "nsflags.h" +#include "nulstr-util.h" #include "process-util.h" #include "seccomp-util.h" #include "set.h" #include "string-util.h" #include "strv.h" -#include "util.h" -#include "errno-list.h" const uint32_t seccomp_local_archs[] = { diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 5c2d00af88..875d0d56c5 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -19,15 +19,15 @@ #include "ima-util.h" #include "log.h" #include "macro.h" +#include "nulstr-util.h" #include "selinux-util.h" #include "set.h" #include "smack-util.h" #include "string-util.h" #include "strv.h" +#include "tests.h" #include "tomoyo-util.h" #include "user-util.h" -#include "tests.h" -#include "util.h" #include "virt.h" static void test_condition_test_path(void) { diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index 5376aa84c4..325c3b32cc 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -3,11 +3,11 @@ #include "alloc-util.h" #include "hashmap.h" #include "log.h" +#include "nulstr-util.h" #include "stdio-util.h" #include "string-util.h" #include "strv.h" #include "tests.h" -#include "util.h" void test_hashmap_funcs(void); diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c index 65f1aae5a7..d79481853a 100644 --- a/src/test/test-seccomp.c +++ b/src/test/test-seccomp.c @@ -16,6 +16,7 @@ #include "memory-util.h" #include "missing.h" #include "nsflags.h" +#include "nulstr-util.h" #include "process-util.h" #include "raw-clone.h" #include "seccomp-util.h" diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 31ef1abb44..18ad03669c 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -4,10 +4,10 @@ #include "alloc-util.h" #include "escape.h" +#include "nulstr-util.h" #include "specifier.h" #include "string-util.h" #include "strv.h" -#include "util.h" static void test_specifier_printf(void) { static const Specifier table[] = { |