mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
util: split out nulstr related stuff to nulstr-util.[ch]
This commit is contained in:
parent
090a9c1eba
commit
d8b4d14df4
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
17
src/basic/nulstr-util.c
Normal file
17
src/basic/nulstr-util.c
Normal file
@ -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;
|
||||
}
|
13
src/basic/nulstr-util.h
Normal file
13
src/basic/nulstr-util.h
Normal file
@ -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);
|
@ -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"
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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[] =
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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] = {
|
||||
|
@ -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[] = {
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user