]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 Dec 2025 16:06:38 +0000 (17:06 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Jan 2026 19:05:45 +0000 (04:05 +0900)
Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes

139 files changed:
src/analyze/analyze-verify-util.h
src/basic/ansi-color.h
src/basic/architecture.h
src/basic/basic-forward.h
src/basic/cgroup-util.h
src/basic/compress.h
src/basic/confidential-virt.h
src/basic/locale-util.h
src/basic/log.h
src/basic/os-util.h
src/basic/process-util.h
src/basic/rlimit-util.h
src/basic/runtime-scope.h
src/basic/signal-util.h
src/basic/socket-util.h
src/basic/stat-util.h
src/basic/syslog-util.h
src/basic/time-util.h
src/basic/unit-def.h
src/basic/virt.h
src/boot/efi-log.h
src/boot/efi.h
src/boot/secure-boot.h
src/core/automount.h
src/core/cgroup.h
src/core/crash-handler.h
src/core/emergency-action.h
src/core/execute.h
src/core/job.h
src/core/kill.h
src/core/manager.h
src/core/mount.h
src/core/namespace.h
src/core/path.h
src/core/scope.h
src/core/service.h
src/core/show-status.h
src/core/socket.h
src/core/swap.h
src/core/timer.h
src/core/unit.h
src/cryptenroll/cryptenroll.h
src/fundamental/string-table-fundamental.h [new file with mode: 0644]
src/home/homed-home.h
src/import/import-compress.h
src/journal/journald-config.h
src/libsystemd-network/dhcp-client-internal.h
src/libsystemd-network/dhcp-duid-internal.h
src/libsystemd-network/dhcp6-protocol.h
src/libsystemd-network/lldp-rx-internal.h
src/libsystemd-network/ndisc-internal.h
src/libsystemd-network/ndisc-router-internal.h
src/libsystemd/sd-device/device-private.h
src/libsystemd/sd-journal/audit-type.h
src/libsystemd/sd-journal/journal-file.h
src/libsystemd/sd-network/network-util.h
src/login/logind-action.h
src/login/logind-inhibit.h
src/login/logind-session.h
src/login/logind-user.h
src/machine/image.h
src/machine/machine.h
src/network/netdev/bareudp.h
src/network/netdev/bridge.h
src/network/netdev/fou-tunnel.h
src/network/netdev/geneve.h
src/network/netdev/hsr.h
src/network/netdev/netdev-util.h
src/network/netdev/netdev.h
src/network/netdev/tunnel.h
src/network/netdev/vxlan.h
src/network/networkd-dhcp-common.h
src/network/networkd-dhcp6.h
src/network/networkd-dns.h
src/network/networkd-ipv6ll.h
src/network/networkd-link.h
src/network/networkd-lldp-rx.h
src/network/networkd-network.h
src/network/networkd-queue.h
src/network/networkd-radv.h
src/network/networkd-route-util.h
src/network/networkd-routing-policy-rule.h
src/network/networkd-sysctl.h
src/network/networkd-util.h
src/nspawn/nspawn-settings.h
src/portable/portable.h
src/resolve/resolved-dns-dnssec.h
src/resolve/resolved-dns-scope.h
src/resolve/resolved-dns-server.h
src/resolve/resolved-dns-stub.h
src/resolve/resolved-dns-transaction.h
src/resolve/resolved-resolv-conf.h
src/shared/bond-util.h
src/shared/boot-entry.h
src/shared/bootspec.h
src/shared/bpf-program.h
src/shared/bridge-util.h
src/shared/bus-unit-util.h
src/shared/bus-util.h
src/shared/condition.h
src/shared/coredump-util.h
src/shared/discover-image.h
src/shared/dns-packet.h
src/shared/dns-rr.h
src/shared/dns-type.h
src/shared/ethtool-util.h
src/shared/exec-util.h
src/shared/exit-status.h
src/shared/factory-reset.h
src/shared/firewall-util.h
src/shared/geneve-util.h
src/shared/gpt.h
src/shared/hostname-setup.h
src/shared/import-util.h
src/shared/install.h
src/shared/ioprio-util.h
src/shared/ipvlan-util.h
src/shared/kernel-image.h
src/shared/macvlan-util.h
src/shared/netif-naming-scheme.h
src/shared/netif-sriov.h
src/shared/numa-util.h
src/shared/open-file.h
src/shared/output-mode.h
src/shared/resolve-util.h
src/shared/seccomp-util.h
src/shared/securebits-util.h
src/shared/sleep-config.h
src/shared/socket-label.h
src/shared/tpm2-event-log.h
src/shared/tpm2-util.h
src/shared/user-record.h
src/shared/volatile-util.h
src/shared/wifi-util.h
src/sysupdate/sysupdate-resource.h
src/udev/net/link-config.h
src/udev/udev-rules.h
src/vmspawn/vmspawn-settings.h
src/vmspawn/vmspawn-util.h

index 66fb2acd5aa6bd0e8546900e836eb2f510bcabb6..b08c9453abc004d3c22fcf2b965ebcc0ccba3c3b 100644 (file)
@@ -19,5 +19,4 @@ int verify_prepare_filename(const char *filename, char **ret);
 int verify_executable(Unit *u, const ExecCommand *exec, const char *root);
 int verify_units(char **filenames, RuntimeScope scope, bool check_man, bool run_generators, RecursiveErrors recursive_errors, const char *root);
 
-const char* recursive_errors_to_string(RecursiveErrors i) _const_;
-RecursiveErrors recursive_errors_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(recursive_errors, RecursiveErrors);
index c81120d2993dbe32e05fe3718fe2c603d24bc364..d8620c0f5252015c0f3085ba64d1c9430e036d0a 100644 (file)
@@ -13,8 +13,7 @@ typedef enum ColorMode {
         _COLOR_MODE_INVALID = -EINVAL,
 } ColorMode;
 
-const char* color_mode_to_string(ColorMode m) _const_;
-ColorMode color_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(color_mode, ColorMode);
 
 ColorMode get_color_mode(void);
 static inline bool colors_enabled(void) {
index d7c3f23c3ddbf0198ef2d8420c64531626097193..467e5acbbf37d20b8d4f4bba6e9aaefd849512a7 100644 (file)
@@ -242,5 +242,4 @@ Architecture uname_architecture(void);
 #  error "Please register your architecture here!"
 #endif
 
-const char* architecture_to_string(Architecture a) _const_;
-Architecture architecture_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(architecture, Architecture);
index d26cc5fe9b2a4afe4ac7058912e3057f65a6ca53..4231f10a59e1505466248e1f93cf33b9f19ad568 100644 (file)
@@ -3,20 +3,21 @@
 
 /* IWYU pragma: always_keep */
 
-#include <errno.h>              /* IWYU pragma: export */
-#include <inttypes.h>           /* IWYU pragma: export */
-#include <limits.h>             /* IWYU pragma: export */
-#include <paths.h>              /* IWYU pragma: export */
-#include <stdarg.h>             /* IWYU pragma: export */
-#include <stdbool.h>            /* IWYU pragma: export */
-#include <stddef.h>             /* IWYU pragma: export */
-#include <stdint.h>             /* IWYU pragma: export */
-#include <sys/types.h>          /* IWYU pragma: export */
-#include <uchar.h>              /* IWYU pragma: export */
-
-#include "assert-util.h"        /* IWYU pragma: export */
-#include "cleanup-util.h"       /* IWYU pragma: export */
-#include "macro.h"              /* IWYU pragma: export */
+#include <errno.h>                      /* IWYU pragma: export */
+#include <inttypes.h>                   /* IWYU pragma: export */
+#include <limits.h>                     /* IWYU pragma: export */
+#include <paths.h>                      /* IWYU pragma: export */
+#include <stdarg.h>                     /* IWYU pragma: export */
+#include <stdbool.h>                    /* IWYU pragma: export */
+#include <stddef.h>                     /* IWYU pragma: export */
+#include <stdint.h>                     /* IWYU pragma: export */
+#include <sys/types.h>                  /* IWYU pragma: export */
+#include <uchar.h>                      /* IWYU pragma: export */
+
+#include "assert-util.h"                /* IWYU pragma: export */
+#include "cleanup-util.h"               /* IWYU pragma: export */
+#include "macro.h"                      /* IWYU pragma: export */
+#include "string-table-fundamental.h"   /* IWYU pragma: export */
 
 /* Generic types */
 
index fd2317cf037c85d3b4c17b8759e5483eaddf8b65..641a179526924c317f2c0da13bdd25e666b50afb 100644 (file)
@@ -95,8 +95,7 @@ typedef enum CGroupIOLimitType {
 
 extern const uint64_t cgroup_io_limit_defaults[_CGROUP_IO_LIMIT_TYPE_MAX];
 
-const char* cgroup_io_limit_type_to_string(CGroupIOLimitType t) _const_;
-CGroupIOLimitType cgroup_io_limit_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_io_limit_type, CGroupIOLimitType);
 void cgroup_io_limits_list(void);
 
 /* Special values for the io.bfq.weight attribute */
@@ -243,8 +242,7 @@ int cg_mask_to_string(CGroupMask mask, char **ret);
 
 bool cg_kill_supported(void);
 
-const char* cgroup_controller_to_string(CGroupController c) _const_;
-CGroupController cgroup_controller_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController);
 
 typedef enum ManagedOOMMode {
         MANAGED_OOM_AUTO,
@@ -253,8 +251,7 @@ typedef enum ManagedOOMMode {
         _MANAGED_OOM_MODE_INVALID = -EINVAL,
 } ManagedOOMMode;
 
-const char* managed_oom_mode_to_string(ManagedOOMMode m) _const_;
-ManagedOOMMode managed_oom_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(managed_oom_mode, ManagedOOMMode);
 
 typedef enum ManagedOOMPreference {
         MANAGED_OOM_PREFERENCE_NONE = 0,
@@ -264,5 +261,4 @@ typedef enum ManagedOOMPreference {
         _MANAGED_OOM_PREFERENCE_INVALID = -EINVAL,
 } ManagedOOMPreference;
 
-const char* managed_oom_preference_to_string(ManagedOOMPreference a) _const_;
-ManagedOOMPreference managed_oom_preference_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(managed_oom_preference, ManagedOOMPreference);
index 6a7486af0ce7e348636472240c8d99756a4fae2e..43885a7eedb5a4a6a098fa75a59cd8914ea2a12e 100644 (file)
@@ -12,10 +12,8 @@ typedef enum Compression {
         _COMPRESSION_INVALID = -EINVAL,
 } Compression;
 
-const char* compression_to_string(Compression compression) _const_;
-Compression compression_from_string(const char *s) _pure_;
-const char* compression_lowercase_to_string(Compression compression) _const_;
-Compression compression_lowercase_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(compression, Compression);
+DECLARE_STRING_TABLE_LOOKUP(compression_lowercase, Compression);
 
 bool compression_supported(Compression c);
 
index 67206cbb292394d3d33ada54be120dfca90110cf..446080de3595f4344760cb635df540743ddb0848 100644 (file)
@@ -20,5 +20,4 @@ typedef enum ConfidentialVirtualization {
 
 ConfidentialVirtualization detect_confidential_virtualization(void);
 
-const char* confidential_virtualization_to_string(ConfidentialVirtualization v) _const_;
-ConfidentialVirtualization confidential_virtualization_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(confidential_virtualization, ConfidentialVirtualization);
index b446ea73ff032b5c0face94dfd089830863679d1..bf5cbcb439220b8bf98ec3bb49e13fba781a1c94 100644 (file)
@@ -36,8 +36,7 @@ int locale_is_installed(const char *name);
 
 bool is_locale_utf8(void);
 
-const char* locale_variable_to_string(LocaleVariable i) _const_;
-LocaleVariable locale_variable_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(locale_variable, LocaleVariable);
 
 static inline void freelocalep(locale_t *p) {
         if (*p == (locale_t) 0)
index 616cb8b92919d8e42bdcf7e6c35a68c231589d6f..46a4339de5565b4065736ccc0d0e498c56c596ec 100644 (file)
@@ -40,8 +40,7 @@ static inline void clear_log_syntax_callback(dummy_t *dummy) {
           set_log_syntax_callback(/* cb= */ NULL, /* userdata= */ NULL);
 }
 
-const char* log_target_to_string(LogTarget target) _const_;
-LogTarget log_target_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(log_target, LogTarget);
 void log_set_target(LogTarget target);
 void log_set_target_and_open(LogTarget target);
 int log_set_target_from_string(const char *e);
index 79cbe25a49fdc80d9b2a91919dffac915634366f..02d2c9540f2de74d87520e15d8456a9254174b73 100644 (file)
@@ -14,8 +14,7 @@ typedef enum ImageClass {
         _IMAGE_CLASS_INVALID = -EINVAL,
 } ImageClass;
 
-const char* image_class_to_string(ImageClass cl) _const_;
-ImageClass image_class_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(image_class, ImageClass);
 
 /* The *_extension_release flavours will look for /usr/lib/extension-release/extension-release.NAME
  * for sysext images and for /etc/extension-release.d/extension-release.NAME for confext images
index c088b468b7cc192a6daedcd71905403f6e8ba9e2..ecd010f38f3f2745ce7bd97fa7bcc381b30872e7 100644 (file)
@@ -107,11 +107,8 @@ const char* personality_to_string(unsigned long);
 int safe_personality(unsigned long p);
 int opinionated_personality(unsigned long *ret);
 
-const char* sigchld_code_to_string(int i) _const_;
-int sigchld_code_from_string(const char *s) _pure_;
-
-int sched_policy_to_string_alloc(int i, char **ret);
-int sched_policy_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(sigchld_code, int);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int);
 
 static inline pid_t PTR_TO_PID(const void *p) {
         return (pid_t) ((uintptr_t) p);
index 59e9532858f16de3da62fc53792109752df5d110..f6a936bf3fca71340b7180c4ac1b745bb4da9224 100644 (file)
@@ -7,8 +7,7 @@
 
 #define _RLIMIT_MAX RLIMIT_NLIMITS
 
-const char* rlimit_to_string(int i) _const_;
-int rlimit_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(rlimit, int);
 int rlimit_from_string_harder(const char *s) _pure_;
 void rlimits_list(const char *prefix);
 
index 4729fa1a95842c056b3a396047c42069919707a2..8a6313d245291d581db94fcb92e77448bdc73fff 100644 (file)
@@ -11,10 +11,8 @@ typedef enum RuntimeScope {
         _RUNTIME_SCOPE_INVALID = -EINVAL,
 } RuntimeScope;
 
-const char* runtime_scope_to_string(RuntimeScope scope) _const_;
-RuntimeScope runtime_scope_from_string(const char *s) _const_;
-
-const char* runtime_scope_cmdline_option_to_string(RuntimeScope scope) _const_;
+DECLARE_STRING_TABLE_LOOKUP(runtime_scope, RuntimeScope);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(runtime_scope_cmdline_option, RuntimeScope);
 
 static inline mode_t runtime_scope_to_socket_mode(RuntimeScope scope) {
         /* Returns the right socket mode to use for binding AF_UNIX sockets intended for the specified
index 298bd409a0d456d14e20afc807d5b73f6e8377a6..c022da62950511ec56bc947e8dac235a43a36292 100644 (file)
@@ -31,8 +31,7 @@ int sigset_add_many_internal(sigset_t *ss, ...);
 int sigprocmask_many_internal(int how, sigset_t *ret_old_mask, ...);
 #define sigprocmask_many(...) sigprocmask_many_internal(__VA_ARGS__, -1)
 
-const char* signal_to_string(int signo) _const_;
-int signal_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(signal, int);
 
 void nop_signal_handler(int sig);
 
index 69b2409d4b3e4c2075e08ddbd18d8bd09194bafa..dc6d2a0fc3c9c03562998a4332a57293f42b6e16 100644 (file)
@@ -55,8 +55,7 @@ typedef struct SocketAddress {
 
 #define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
 
-const char* socket_address_type_to_string(int t) _const_;
-int socket_address_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_address_type, int);
 
 int sockaddr_un_unlink(const struct sockaddr_un *sa);
 
@@ -87,8 +86,7 @@ int getsockname_pretty(int fd, char **ret);
 
 int socknameinfo_pretty(const struct sockaddr *sa, socklen_t salen, char **_ret);
 
-int netlink_family_to_string_alloc(int i, char **ret);
-int netlink_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(netlink_family, int);
 
 bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b);
 
@@ -101,8 +99,7 @@ static inline int fd_increase_rxbuf(int fd, size_t n) {
         return fd_set_rcvbuf(fd, n, true);
 }
 
-int ip_tos_to_string_alloc(int i, char **ret);
-int ip_tos_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int);
 
 typedef enum {
         IFNAME_VALID_ALTERNATIVE = 1 << 0, /* Allow "altnames" too */
index 490ee96c5f1582da8aabb2ddb691324e3abb1dfe..395e391786c122a07ea2eddc388a7eff0f214610 100644 (file)
@@ -97,8 +97,7 @@ void inode_hash_func(const struct stat *q, struct siphash *state);
 int inode_compare_func(const struct stat *a, const struct stat *b);
 extern const struct hash_ops inode_hash_ops;
 
-const char* inode_type_to_string(mode_t m) _const_;
-mode_t inode_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(inode_type, mode_t);
 
 /* Macros that check whether the stat/statx structures have been initialized already. For "struct stat" we
  * use a check for .st_dev being non-zero, since the kernel unconditionally fills that in, mapping the file
index b4bad9fca92e9f0bb42126791dbf1627be2ae970..64f237d6a1390ff97959ecf3af1df0211518dcd6 100644 (file)
@@ -3,12 +3,10 @@
 
 #include "basic-forward.h"
 
-int log_facility_unshifted_to_string_alloc(int i, char **ret);
-int log_facility_unshifted_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int);
 bool log_facility_unshifted_is_valid(int faciliy);
 
-int log_level_to_string_alloc(int i, char **ret);
-int log_level_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int);
 bool log_level_is_valid(int level);
 
 int syslog_parse_priority(const char **p, int *priority, bool with_facility);
index dc6427d98a8819168807fc332ada0a3c6cafa071..091b79ff30f6a90c6fd4c4e0f258c7f6c5bfefbe 100644 (file)
@@ -232,5 +232,4 @@ int usleep_safe(usec_t usec);
 
 int time_change_fd(void);
 
-const char* timestamp_style_to_string(TimestampStyle t) _const_;
-TimestampStyle timestamp_style_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(timestamp_style, TimestampStyle);
index be2d6e1af669023a57ea0d353d47780d2262324b..d346174d56fcff17a4d7c18529846aeedb502f95 100644 (file)
@@ -313,67 +313,47 @@ int unit_name_from_dbus_path(const char *path, char **name);
 const char* unit_dbus_interface_from_type(UnitType t);
 const char* unit_dbus_interface_from_name(const char *name);
 
-const char* unit_type_to_string(UnitType i) _const_;
-UnitType unit_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_type, UnitType);
 void unit_types_list(void);
 
-const char* unit_load_state_to_string(UnitLoadState i) _const_;
-UnitLoadState unit_load_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
 
-const char* unit_active_state_to_string(UnitActiveState i) _const_;
-UnitActiveState unit_active_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
 
-const char* freezer_state_to_string(FreezerState i) _const_;
-FreezerState freezer_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(freezer_state, FreezerState);
 FreezerState freezer_state_finish(FreezerState state) _const_;
 FreezerState freezer_state_objective(FreezerState state) _const_;
 
-const char* unit_marker_to_string(UnitMarker m) _const_;
-UnitMarker unit_marker_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_marker, UnitMarker);
 
-const char* automount_state_to_string(AutomountState i) _const_;
-AutomountState automount_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
 
-const char* device_state_to_string(DeviceState i) _const_;
-DeviceState device_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(device_state, DeviceState);
 
-const char* mount_state_to_string(MountState i) _const_;
-MountState mount_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(mount_state, MountState);
 
-const char* path_state_to_string(PathState i) _const_;
-PathState path_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(path_state, PathState);
 
-const char* scope_state_to_string(ScopeState i) _const_;
-ScopeState scope_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(scope_state, ScopeState);
 
-const char* service_state_to_string(ServiceState i) _const_;
-ServiceState service_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_state, ServiceState);
 
-const char* slice_state_to_string(SliceState i) _const_;
-SliceState slice_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(slice_state, SliceState);
 
-const char* socket_state_to_string(SocketState i) _const_;
-SocketState socket_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_state, SocketState);
 
-const char* swap_state_to_string(SwapState i) _const_;
-SwapState swap_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(swap_state, SwapState);
 
-const char* target_state_to_string(TargetState i) _const_;
-TargetState target_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(target_state, TargetState);
 
-const char* timer_state_to_string(TimerState i) _const_;
-TimerState timer_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(timer_state, TimerState);
 
-const char* unit_dependency_to_string(UnitDependency i) _const_;
-UnitDependency unit_dependency_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
 
-const char* notify_access_to_string(NotifyAccess i) _const_;
-NotifyAccess notify_access_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);
 
-const char* job_mode_to_string(JobMode t) _const_;
-JobMode job_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(job_mode, JobMode);
 
-const char* exec_directory_type_to_string(ExecDirectoryType i) _const_;
-ExecDirectoryType exec_directory_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_directory_type, ExecDirectoryType);
 
 Glyph unit_active_state_to_glyph(UnitActiveState state);
index b34bfd8261faa46605ff1c629ddbdcf56f11f171..99877044e0a5bab25017bc28cf5f99548390186a 100644 (file)
@@ -62,6 +62,5 @@ Virtualization detect_virtualization(void);
 int running_in_userns(void);
 int running_in_chroot(void);
 
-const char* virtualization_to_string(Virtualization v) _const_;
-Virtualization virtualization_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(virtualization, Virtualization);
 bool has_cpu_with_flag(const char *flag);
index 2c340a4a9dcf365676eecc04cc0cca121ac24ddb..5458f90109a0b6196a6a9c880caea53f4089f711 100644 (file)
@@ -34,8 +34,7 @@ typedef enum LogLevel {
         _LOG_INVALID = -1,
 } LogLevel;
 
-LogLevel log_level_from_string(const char *s) _pure_;
-const char* log_level_to_string(LogLevel l) _const_;
+DECLARE_STRING_TABLE_LOOKUP(log_level, LogLevel);
 
 LogLevel log_get_max_level(void) _pure_;
 int log_set_max_level(LogLevel level);
index 1832df980c3eb4a53d2d27b56764d391f9e01667..eddaad1eeeaaab071bfb8f15c123c49f8b416937 100644 (file)
@@ -13,6 +13,7 @@
 #include "cleanup-fundamental.h"        /* IWYU pragma: export */
 #include "efi-fundamental.h"            /* IWYU pragma: export */
 #include "macro-fundamental.h"          /* IWYU pragma: export */
+#include "string-table-fundamental.h"   /* IWYU pragma: export */
 
 #if SD_BOOT
 /* uchar.h/wchar.h are not suitable for freestanding environments. */
index cf9c925758d5c226457550d103cdab2a409cf54c..03bead27124d8d2a0896ca30524163a42718b58f 100644 (file)
@@ -41,5 +41,5 @@ void install_security_override(security_validator_t validator, const void *valid
 void uninstall_security_override(void);
 bool security_override_available(void);
 
-const char* secure_boot_enroll_to_string(secure_boot_enroll e) _const_;
-const char* secure_boot_enroll_action_to_string(secure_boot_enroll_action e) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(secure_boot_enroll, secure_boot_enroll);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(secure_boot_enroll_action, secure_boot_enroll_action);
index 8dd70ad8b5e4652c8746489cc8202b15c9315a5c..b9e463de5bcf8f0a8b8c7d71f2bffac4139bee1b 100644 (file)
@@ -38,7 +38,6 @@ typedef struct Automount {
 
 extern const UnitVTable automount_vtable;
 
-const char* automount_result_to_string(AutomountResult i) _const_;
-AutomountResult automount_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(automount_result, AutomountResult);
 
 DEFINE_CAST(AUTOMOUNT, Automount);
index 4f1a77392f31567c47e344ea7aa214d9b1a5ab83..6c45b72f1172283f099719ef8c1c9a8b382eb6fa 100644 (file)
@@ -450,8 +450,7 @@ void unit_invalidate_cgroup_bpf_firewall(Unit *u);
 
 void manager_invalidate_startup_units(Manager *m);
 
-const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
-CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_device_policy, CGroupDevicePolicy);
 
 void unit_cgroup_catchup(Unit *u);
 
@@ -461,8 +460,7 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name);
 
 int unit_cgroup_freezer_action(Unit *u, FreezerAction action);
 
-const char* freezer_action_to_string(FreezerAction a) _const_;
-FreezerAction freezer_action_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(freezer_action, FreezerAction);
 
 CGroupRuntime* cgroup_runtime_new(void);
 CGroupRuntime* cgroup_runtime_free(CGroupRuntime *crt);
@@ -471,20 +469,14 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(CGroupRuntime*, cgroup_runtime_free);
 int cgroup_runtime_serialize(Unit *u, FILE *f, FDSet *fds);
 int cgroup_runtime_deserialize_one(Unit *u, const char *key, const char *value, FDSet *fds);
 
-const char* cgroup_pressure_watch_to_string(CGroupPressureWatch a) _const_;
-CGroupPressureWatch cgroup_pressure_watch_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_pressure_watch, CGroupPressureWatch);
 
-const char* cgroup_device_permissions_to_string(CGroupDevicePermissions p) _const_;
-CGroupDevicePermissions cgroup_device_permissions_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_device_permissions, CGroupDevicePermissions);
 
-const char* cgroup_ip_accounting_metric_to_string(CGroupIPAccountingMetric m) _const_;
-CGroupIPAccountingMetric cgroup_ip_accounting_metric_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_ip_accounting_metric, CGroupIPAccountingMetric);
 
-const char* cgroup_io_accounting_metric_to_string(CGroupIOAccountingMetric m) _const_;
-CGroupIOAccountingMetric cgroup_io_accounting_metric_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_io_accounting_metric, CGroupIOAccountingMetric);
 
-const char* cgroup_effective_limit_type_to_string(CGroupLimitType m) _const_;
-CGroupLimitType cgroup_effective_limit_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_effective_limit_type, CGroupLimitType);
 
-const char* cgroup_memory_accounting_metric_to_string(CGroupMemoryAccountingMetric m) _const_;
-CGroupMemoryAccountingMetric cgroup_memory_accounting_metric_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(cgroup_memory_accounting_metric, CGroupMemoryAccountingMetric);
index 2fad083ace354b78275b60da4b7ee883bbde819b..a24e56ff47fd3f4a291b8853f79a59a3ad4dc1a1 100644 (file)
@@ -11,8 +11,7 @@ typedef enum CrashAction {
         _CRASH_ACTION_INVALID = -EINVAL,
 } CrashAction;
 
-const char* crash_action_to_string(CrashAction action);
-CrashAction crash_action_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(crash_action, CrashAction);
 
 _noreturn_ void freeze_or_exit_or_reboot(void);
 void install_crash_handler(void);
index f993a5f06e5d0113b1e326e0effde01034520aac..17f306507f39cb751f6b5388ab83781afaa51751 100644 (file)
@@ -40,7 +40,6 @@ void emergency_action(
                 int exit_status,
                 const char *reason);
 
-const char* emergency_action_to_string(EmergencyAction i) _const_;
-EmergencyAction emergency_action_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(emergency_action, EmergencyAction);
 
 int parse_emergency_action(const char *value, RuntimeScope runtime_scope, EmergencyAction *ret);
index 2690f2336e3a5c67b3696b07b70d852ac8d0a6c2..ae26be6781c2bee98a38a751c869d43b9e00288c 100644 (file)
@@ -597,31 +597,23 @@ int exec_directory_add(ExecDirectory *d, const char *path, const char *symlink,
 void exec_directory_sort(ExecDirectory *d);
 bool exec_directory_is_private(const ExecContext *context, ExecDirectoryType type);
 
-ExecCleanMask exec_clean_mask_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(exec_clean_mask, ExecCleanMask);
 
-const char* exec_output_to_string(ExecOutput i) _const_;
-ExecOutput exec_output_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_output, ExecOutput);
 
-const char* exec_input_to_string(ExecInput i) _const_;
-ExecInput exec_input_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_input, ExecInput);
 
-const char* exec_utmp_mode_to_string(ExecUtmpMode i) _const_;
-ExecUtmpMode exec_utmp_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_utmp_mode, ExecUtmpMode);
 
-const char* exec_preserve_mode_to_string(ExecPreserveMode i) _const_;
-ExecPreserveMode exec_preserve_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_preserve_mode, ExecPreserveMode);
 
-const char* exec_keyring_mode_to_string(ExecKeyringMode i) _const_;
-ExecKeyringMode exec_keyring_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_keyring_mode, ExecKeyringMode);
 
-const char* exec_directory_type_symlink_to_string(ExecDirectoryType i) _const_;
-ExecDirectoryType exec_directory_type_symlink_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_directory_type_symlink, ExecDirectoryType);
 
-const char* exec_directory_type_mode_to_string(ExecDirectoryType i) _const_;
-ExecDirectoryType exec_directory_type_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_directory_type_mode, ExecDirectoryType);
 
-const char* exec_resource_type_to_string(ExecDirectoryType i) _const_;
-ExecDirectoryType exec_resource_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(exec_resource_type, ExecDirectoryType);
 
 bool exec_needs_mount_namespace(const ExecContext *context, const ExecParameters *params, const ExecRuntime *runtime);
 bool exec_needs_network_namespace(const ExecContext *context);
index 4c2f78815b0be5faf92e194b5d96a387cf000dce..d8aa6ce17c53ad87ba9865a1a4f6856025bfe273 100644 (file)
@@ -209,14 +209,11 @@ void job_add_to_gc_queue(Job *j);
 int job_get_before(Job *j, Job*** ret);
 int job_get_after(Job *j, Job*** ret);
 
-const char* job_type_to_string(JobType t) _const_;
-JobType job_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(job_type, JobType);
 
-const char* job_state_to_string(JobState t) _const_;
-JobState job_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(job_state, JobState);
 
-const char* job_result_to_string(JobResult t) _const_;
-JobResult job_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(job_result, JobResult);
 
 const char* job_type_to_access_method(JobType t);
 
index ac1163737f58d1eecea8af81e4f781061b3149c3..fcb090da63cc2eb43fbce3683c4a9029e1a6bc1e 100644 (file)
@@ -40,11 +40,9 @@ typedef enum KillWhom {
 void kill_context_init(KillContext *c);
 void kill_context_dump(KillContext *c, FILE *f, const char *prefix);
 
-const char* kill_mode_to_string(KillMode k) _const_;
-KillMode kill_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(kill_mode, KillMode);
 
-const char* kill_whom_to_string(KillWhom k) _const_;
-KillWhom kill_whom_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
 
 static inline int restart_kill_signal(const KillContext *c) {
         if (c->restart_kill_signal != 0)
index 90163d5842edfc72f85a85e6c07f318d7d646824..c764f411086eaac28ecefe7d0c92857faa3f8273 100644 (file)
@@ -625,14 +625,11 @@ void manager_restore_original_log_target(Manager *m);
 const char* manager_get_confirm_spawn(Manager *m);
 void manager_disable_confirm_spawn(void);
 
-const char* manager_state_to_string(ManagerState m) _const_;
-ManagerState manager_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(manager_state, ManagerState);
 
-const char* manager_objective_to_string(ManagerObjective m) _const_;
-ManagerObjective manager_objective_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(manager_objective, ManagerObjective);
 
-const char* manager_timestamp_to_string(ManagerTimestamp m) _const_;
-ManagerTimestamp manager_timestamp_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(manager_timestamp, ManagerTimestamp);
 ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s);
 
 usec_t manager_get_watchdog(Manager *m, WatchdogType t);
index d9f8d4f663b782dc73bdf83821f23d73914edf7e..3193297e0c7f7b7b405ad54ea7df242ead04f106 100644 (file)
@@ -99,10 +99,8 @@ char* mount_get_what_escaped(const Mount *m);
 char* mount_get_options_escaped(const Mount *m);
 const char* mount_get_fstype(const Mount *m);
 
-const char* mount_exec_command_to_string(MountExecCommand i) _const_;
-MountExecCommand mount_exec_command_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
 
-const char* mount_result_to_string(MountResult i) _const_;
-MountResult mount_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(mount_result, MountResult);
 
 DEFINE_CAST(MOUNT, Mount);
index 86c09ec2315cfebd3cc1fb0d71cecf5bd3d39142..aae43db3896c79fb5ae41091ffa2f415a3f5c72d 100644 (file)
@@ -221,35 +221,25 @@ int setup_tmp_dirs(
 int setup_shareable_ns(int ns_storage_socket[static 2], unsigned long nsflag);
 int open_shareable_ns_path(int netns_storage_socket[static 2], const char *path, unsigned long nsflag);
 
-const char* protect_home_to_string(ProtectHome p) _const_;
-ProtectHome protect_home_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(protect_home, ProtectHome);
 
-const char* protect_hostname_to_string(ProtectHostname p) _const_;
-ProtectHostname protect_hostname_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(protect_hostname, ProtectHostname);
 
-const char* protect_system_to_string(ProtectSystem p) _const_;
-ProtectSystem protect_system_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(protect_system, ProtectSystem);
 
-const char* protect_proc_to_string(ProtectProc i) _const_;
-ProtectProc protect_proc_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(protect_proc, ProtectProc);
 
-const char* proc_subset_to_string(ProcSubset i) _const_;
-ProcSubset proc_subset_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(proc_subset, ProcSubset);
 
-const char* private_bpf_to_string(PrivateBPF i) _const_;
-PrivateBPF private_bpf_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(private_bpf, PrivateBPF);
 
-const char* bpf_delegate_cmd_to_string(uint64_t u) _const_;
-uint64_t bpf_delegate_cmd_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bpf_delegate_cmd, uint64_t);
 
-const char* bpf_delegate_map_type_to_string(uint64_t u) _const_;
-uint64_t bpf_delegate_map_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bpf_delegate_map_type, uint64_t);
 
-const char* bpf_delegate_prog_type_to_string(uint64_t u) _const_;
-uint64_t bpf_delegate_prog_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bpf_delegate_prog_type, uint64_t);
 
-const char* bpf_delegate_attach_type_to_string(uint64_t u) _const_;
-uint64_t bpf_delegate_attach_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bpf_delegate_attach_type, uint64_t);
 
 char* bpf_delegate_to_string(uint64_t u, const char * (*parser)(uint64_t) _const_);
 int bpf_delegate_from_string(const char *s, uint64_t *ret, uint64_t (*parser)(const char *));
@@ -286,17 +276,13 @@ static inline char * bpf_delegate_attachments_to_string(uint64_t u) {
         return bpf_delegate_to_string(u, bpf_delegate_attach_type_to_string);
 }
 
-const char* private_tmp_to_string(PrivateTmp i) _const_;
-PrivateTmp private_tmp_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(private_tmp, PrivateTmp);
 
-const char* private_users_to_string(PrivateUsers i) _const_;
-PrivateUsers private_users_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(private_users, PrivateUsers);
 
-const char* protect_control_groups_to_string(ProtectControlGroups i) _const_;
-ProtectControlGroups protect_control_groups_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(protect_control_groups, ProtectControlGroups);
 
-const char* private_pids_to_string(PrivatePIDs i) _const_;
-PrivatePIDs private_pids_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(private_pids, PrivatePIDs);
 
 void bind_mount_free_many(BindMount *b, size_t n);
 int bind_mount_add(BindMount **b, size_t *n, const BindMount *item);
index b99e1826a546fab5ac2eebdfc7b3b699ecc3c344..bc69e79d17401a654baa580a19044f850b97fdac 100644 (file)
@@ -76,11 +76,9 @@ void path_free_specs(Path *p);
 extern const UnitVTable path_vtable;
 extern const ActivationDetailsVTable activation_details_path_vtable;
 
-const char* path_type_to_string(PathType i) _const_;
-PathType path_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(path_type, PathType);
 
-const char* path_result_to_string(PathResult i) _const_;
-PathResult path_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(path_result, PathResult);
 
 DEFINE_CAST(PATH, Path);
 DEFINE_ACTIVATION_DETAILS_CAST(ACTIVATION_DETAILS_PATH, ActivationDetailsPath, PATH);
index 0654197094998796cda34672c681c923509d9ba7..d288b183cb5f7afe19bf40e836a0d6c2702f233a 100644 (file)
@@ -46,7 +46,6 @@ extern const UnitVTable scope_vtable;
 
 int scope_abandon(Scope *s);
 
-const char* scope_result_to_string(ScopeResult i) _const_;
-ScopeResult scope_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(scope_result, ScopeResult);
 
 DEFINE_CAST(SCOPE, Scope);
index 7d51c57f6cc5524a84353b77921f9f2ecdf44509..167b7891e08f2b138b80e56dbb3595efbbb5c696 100644 (file)
@@ -270,32 +270,23 @@ usec_t service_restart_usec_next(const Service *s) _pure_;
 
 int service_determine_exec_selinux_label(Service *s, char **ret);
 
-const char* service_restart_to_string(ServiceRestart i) _const_;
-ServiceRestart service_restart_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
 
-const char* service_restart_mode_to_string(ServiceRestartMode i) _const_;
-ServiceRestartMode service_restart_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_restart_mode, ServiceRestartMode);
 
-const char* service_type_to_string(ServiceType i) _const_;
-ServiceType service_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_type, ServiceType);
 
-const char* service_exit_type_to_string(ServiceExitType i) _const_;
-ServiceExitType service_exit_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_exit_type, ServiceExitType);
 
-const char* service_exec_command_to_string(ServiceExecCommand i) _const_;
-ServiceExecCommand service_exec_command_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
 
-const char* service_exec_ex_command_to_string(ServiceExecCommand i) _const_;
-ServiceExecCommand service_exec_ex_command_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_exec_ex_command, ServiceExecCommand);
 
-const char* notify_state_to_string(NotifyState i) _const_;
-NotifyState notify_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(notify_state, NotifyState);
 
-const char* service_result_to_string(ServiceResult i) _const_;
-ServiceResult service_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_result, ServiceResult);
 
-const char* service_timeout_failure_mode_to_string(ServiceTimeoutFailureMode i) _const_;
-ServiceTimeoutFailureMode service_timeout_failure_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(service_timeout_failure_mode, ServiceTimeoutFailureMode);
 
 DEFINE_CAST(SERVICE, Service);
 
index 13c42078d9c1ec5a8c1e6ddc5757d4305fa78e1f..c7ebf7bef3c752e67b0f7b8b9368868e44b938c0 100644 (file)
@@ -31,12 +31,10 @@ typedef enum StatusUnitFormat {
 static inline bool show_status_on(ShowStatus s) {
         return IN_SET(s, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES);
 }
-ShowStatus show_status_from_string(const char *s) _const_;
-const char* show_status_to_string(ShowStatus s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(show_status, ShowStatus);
 int parse_show_status(const char *s, ShowStatus *ret);
 
-StatusUnitFormat status_unit_format_from_string(const char *s) _const_;
-const char* status_unit_format_to_string(StatusUnitFormat s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(status_unit_format, StatusUnitFormat);
 
 int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) _printf_(3,0);
 int status_printf(const char *status, ShowStatusFlags flags, const char *format, ...) _printf_(3,4);
index 57c9be46239c7aabdb7ebee5ba0665178b123ec3..b9010bac49f52d23da59bdd10091a79c70b1f87e 100644 (file)
@@ -204,20 +204,16 @@ const char* socket_fdname(Socket *s);
 
 extern const UnitVTable socket_vtable;
 
-const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
-SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
 
-const char* socket_result_to_string(SocketResult i) _const_;
-SocketResult socket_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
 
 const char* socket_port_type_to_string(SocketPort *p) _pure_;
 SocketType socket_port_type_from_string(const char *s) _pure_;
 
-const char* socket_timestamping_to_string(SocketTimestamping p) _const_;
-SocketTimestamping socket_timestamping_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_timestamping, SocketTimestamping);
 SocketTimestamping socket_timestamping_from_string_harder(const char *s) _pure_;
 
-const char* socket_defer_trigger_to_string(SocketDeferTrigger i) _const_;
-SocketDeferTrigger socket_defer_trigger_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_defer_trigger, SocketDeferTrigger);
 
 DEFINE_CAST(SOCKET, Socket);
index 946a2ac55fb575df486fd2e7990fbfacaaa138e7..4b4da59d8da2f731f12fcd0a297f6de6df79912e 100644 (file)
@@ -94,10 +94,8 @@ int swap_process_device_remove(Manager *m, sd_device *dev);
 int swap_get_priority(const Swap *s);
 const char* swap_get_options(const Swap *s);
 
-const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
-SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(swap_exec_command, SwapExecCommand);
 
-const char* swap_result_to_string(SwapResult i) _const_;
-SwapResult swap_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
 
 DEFINE_CAST(SWAP, Swap);
index afc9d31f067f8212a26da7f59067ae29af2cdffe..70b5dabeb727611ced8c3ef338f7ffeaa72d2b35 100644 (file)
@@ -78,13 +78,11 @@ void timer_free_values(Timer *t);
 extern const UnitVTable timer_vtable;
 extern const ActivationDetailsVTable activation_details_timer_vtable;
 
-const char* timer_base_to_string(TimerBase i) _const_;
-TimerBase timer_base_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
 
 char* timer_base_to_usec_string(TimerBase i);
 
-const char* timer_result_to_string(TimerResult i) _const_;
-TimerResult timer_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
 
 DEFINE_CAST(TIMER, Timer);
 DEFINE_ACTIVATION_DETAILS_CAST(ACTIVATION_DETAILS_TIMER, ActivationDetailsTimer, TIMER);
index dc546116f9965f1546477bd25d50209f5a575175..56bd75b56ee9d62e1ccc2f4a3c84670beebdbcd1 100644 (file)
@@ -1087,12 +1087,10 @@ int unit_compare_priority(Unit *a, Unit *b);
 const char* unit_log_field(const Unit *u);
 const char* unit_invocation_log_field(const Unit *u);
 
-UnitMountDependencyType unit_mount_dependency_type_from_string(const char *s) _const_;
-const char* unit_mount_dependency_type_to_string(UnitMountDependencyType t) _const_;
+DECLARE_STRING_TABLE_LOOKUP(unit_mount_dependency_type, UnitMountDependencyType);
 UnitDependency unit_mount_dependency_type_to_dependency_type(UnitMountDependencyType t) _pure_;
 
-const char* oom_policy_to_string(OOMPolicy i) _const_;
-OOMPolicy oom_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(oom_policy, OOMPolicy);
 
 /* Macros which append UNIT= or USER_UNIT= to the message */
 
@@ -1168,8 +1166,7 @@ OOMPolicy oom_policy_from_string(const char *s) _pure_;
 #define LOG_UNIT_ID(unit) LOG_ITEM("%s%s", unit_log_field((unit)), (unit)->id)
 #define LOG_UNIT_INVOCATION_ID(unit) LOG_ITEM("%s%s", unit_invocation_log_field((unit)), (unit)->invocation_id_string)
 
-const char* collect_mode_to_string(CollectMode m) _const_;
-CollectMode collect_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(collect_mode, CollectMode);
 
 typedef struct UnitForEachDependencyData {
         /* Stores state for the FOREACH macro below for iterating through all deps that have any of the
index 613940fe97cdb972c804aa7d6429696344a1e45f..1066ecc18d9aa9483bfdd628ded4f38d2dd9bf1d 100644 (file)
@@ -30,8 +30,5 @@ typedef enum WipeScope {
         _WIPE_SCOPE_INVALID = -EINVAL,
 } WipeScope;
 
-const char* enroll_type_to_string(EnrollType t);
-EnrollType enroll_type_from_string(const char *s);
-
-const char* luks2_token_type_to_string(EnrollType t);
-EnrollType luks2_token_type_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(enroll_type, EnrollType);
+DECLARE_STRING_TABLE_LOOKUP(luks2_token_type, EnrollType);
diff --git a/src/fundamental/string-table-fundamental.h b/src/fundamental/string-table-fundamental.h
new file mode 100644 (file)
index 0000000..d402515
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "macro-fundamental.h"
+
+#define DECLARE_STRING_TABLE_LOOKUP_TO_STRING(name, type) \
+        const char* name##_to_string(type i) _const_
+
+#define DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) \
+        type name##_from_string(const char *s) _pure_
+
+#define DECLARE_STRING_TABLE_LOOKUP(name, type) \
+        DECLARE_STRING_TABLE_LOOKUP_TO_STRING(name, type); \
+        DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(name, type)
+
+#define DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type) \
+        int name##_to_string_alloc(type i, char **ret)
+
+#define DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name, type) \
+        DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type); \
+        DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(name, type)
index 1f9a5488484e215b6b610956b8b5979e29a8bc66..b31ee08fdacd9a702cfa9cbe3572049f70b11814 100644 (file)
@@ -230,5 +230,4 @@ bool home_shall_rebalance(Home *h);
 
 bool home_is_busy(Home *h);
 
-const char* home_state_to_string(HomeState state);
-HomeState home_state_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(home_state, HomeState);
index 6e7f0e514a1f2840aed3f5513f06f43b12cd3616..647e623266787d9ac5eeee9b4fa6d6a99a27c904 100644 (file)
@@ -51,5 +51,4 @@ int import_compress_init(ImportCompress *c, ImportCompressType t);
 int import_compress(ImportCompress *c, const void *data, size_t size, void **buffer, size_t *buffer_size, size_t *buffer_allocated);
 int import_compress_finish(ImportCompress *c, void **buffer, size_t *buffer_size, size_t *buffer_allocated);
 
-const char* import_compress_type_to_string(ImportCompressType t) _const_;
-ImportCompressType import_compress_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(import_compress_type, ImportCompressType);
index 4aa78105e54fe8199858da3e64b18c82bc3e19e6..4fae67484f5d06051deb422d07ae7948fe73c5fc 100644 (file)
@@ -99,11 +99,9 @@ int manager_dispatch_reload_signal(sd_event_source *s, const struct signalfd_sig
 /* Defined in generated journald-gperf.c */
 const struct ConfigPerfItem* journald_gperf_lookup(const char *str, GPERF_LEN_TYPE length);
 
-const char* storage_to_string(Storage s) _const_;
-Storage storage_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(storage, Storage);
 
-const char* split_mode_to_string(SplitMode s) _const_;
-SplitMode split_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_storage);
 CONFIG_PARSER_PROTOTYPE(config_parse_line_max);
index 16d5ac8630e658f46dadc48234a5e76826e7a73f..f75ca71b4350c2bd8f1d814e3818609e1c0e6f24 100644 (file)
@@ -20,7 +20,7 @@ typedef enum DHCPState {
         _DHCP_STATE_INVALID                     = -EINVAL,
 } DHCPState;
 
-const char* dhcp_state_to_string(DHCPState s) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(dhcp_state, DHCPState);
 
 typedef struct sd_dhcp_client sd_dhcp_client;
 
index 94a119c3e8ad09c3c2d9e35eb59e7d8747a718b6..eca98892791d222ef2ba17e07a89694cbb2b18bd 100644 (file)
@@ -76,7 +76,7 @@ static inline bool duid_data_size_is_valid(size_t size) {
         return size >= MIN_DUID_DATA_LEN && size <= MAX_DUID_DATA_LEN;
 }
 
-const char* duid_type_to_string(DUIDType t) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(duid_type, DUIDType);
 int dhcp_duid_to_string_internal(uint16_t type, const void *data, size_t data_size, char **ret);
 
 int dhcp_identifier_set_iaid(
index 020088ba74cdc1a7fb4fec36de7eeebaf7c246da..74b5b8f5305315dea33833b4ec42932760f37ae1 100644 (file)
@@ -150,9 +150,7 @@ typedef enum DHCP6FQDNFlag {
         DHCP6_FQDN_FLAG_N = 1 << 2,
 } DHCP6FQDNFlag;
 
-const char* dhcp6_state_to_string(DHCP6State s) _const_;
-const char* dhcp6_message_type_to_string(DHCP6MessageType s) _const_;
-DHCP6MessageType dhcp6_message_type_from_string(const char *s) _pure_;
-const char* dhcp6_message_status_to_string(DHCP6Status s) _const_;
-DHCP6Status dhcp6_message_status_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(dhcp6_state, DHCP6State);
+DECLARE_STRING_TABLE_LOOKUP(dhcp6_message_type, DHCP6MessageType);
+DECLARE_STRING_TABLE_LOOKUP(dhcp6_message_status, DHCP6Status);
 int dhcp6_message_status_to_errno(DHCP6Status s);
index a47eede68ac8dbe750514130d1ac237ae48a7dcd..18fd33b742c89386d1ebc30da1e0fe966270a55c 100644 (file)
@@ -33,8 +33,7 @@ struct sd_lldp_rx {
         struct ether_addr filter_address;
 };
 
-const char* lldp_rx_event_to_string(sd_lldp_rx_event_t e) _const_;
-sd_lldp_rx_event_t lldp_rx_event_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(lldp_rx_event, sd_lldp_rx_event_t);
 
 int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, sd_json_variant **ret);
 
index dfa38cd61fc9884b5460c976b1acb46235cdd8a4..a8ec0ee79b6b6908481e89b23c5834747f87385a 100644 (file)
@@ -42,8 +42,7 @@ typedef struct sd_ndisc {
         void *userdata;
 } sd_ndisc;
 
-const char* ndisc_event_to_string(sd_ndisc_event_t e) _const_;
-sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ndisc_event, sd_ndisc_event_t);
 
 #define log_ndisc_errno(ndisc, error, fmt, ...)         \
         log_interface_prefix_full_errno(                \
index 025cc146a42c984f2c478b35508928f63c9d0c19..51cc8aab1b521cc3343271d4da83e01652608894 100644 (file)
@@ -34,4 +34,4 @@ sd_ndisc_router* ndisc_router_new(ICMP6Packet *packet);
 int ndisc_router_parse(sd_ndisc *nd, sd_ndisc_router *rt);
 
 int ndisc_router_flags_to_string(uint64_t flags, char **ret);
-const char* ndisc_router_preference_to_string(int s) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(ndisc_router_preference, int);
index 2bdc0492c6bc1058f29efa6609145068e4da632a..8f88b38c46cd04021646b0a99db1e21ca45dba1a 100644 (file)
@@ -72,5 +72,4 @@ static inline int device_read_db(sd_device *device) {
 int device_read_uevent_file(sd_device *device);
 
 int device_set_action(sd_device *device, sd_device_action_t a);
-sd_device_action_t device_action_from_string(const char *s) _pure_;
-const char* device_action_to_string(sd_device_action_t a) _const_;
+DECLARE_STRING_TABLE_LOOKUP(device_action, sd_device_action_t);
index dd74102049223aa1bfddeba1a7991edb73121176..a92567d184ce1af5049e6a1160b029c3ee14f6bd 100644 (file)
@@ -5,8 +5,7 @@
 
 #include "sd-forward.h"
 
-const char* audit_type_to_string(int type);
-int audit_type_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(audit_type, int);
 
 /* This is inspired by DNS TYPEnnn formatting */
 #define audit_type_name_alloca(type)                                    \
index 1e5993b0a6db065ff4d47198f980ddc5289523b3..b3a620200ae812efe39a1bd83f1511e129d5b452 100644 (file)
@@ -335,7 +335,7 @@ uint64_t journal_file_hash_data(JournalFile *f, const void *data, size_t sz);
 
 bool journal_field_valid(const char *p, size_t l, bool allow_protected);
 
-const char* journal_object_type_to_string(ObjectType type) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(journal_object_type, ObjectType);
 
 static inline Compression COMPRESSION_FROM_OBJECT(const Object *o) {
         assert(o);
index 818c7f73bbfffe60f85cc9330bbc4789ceccecac..18d18b58d081b4ede21ef1ee62524816998e9868 100644 (file)
@@ -73,20 +73,15 @@ typedef enum LinkOnlineState {
         _LINK_ONLINE_STATE_INVALID = -EINVAL,
 } LinkOnlineState;
 
-const char* link_operstate_to_string(LinkOperationalState s) _const_;
-LinkOperationalState link_operstate_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState);
 
-const char* link_carrier_state_to_string(LinkCarrierState s) _const_;
-LinkCarrierState link_carrier_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_carrier_state, LinkCarrierState);
 
-const char* link_required_address_family_to_string(AddressFamily s) _const_;
-AddressFamily link_required_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_required_address_family, AddressFamily);
 
-const char* link_address_state_to_string(LinkAddressState s) _const_;
-LinkAddressState link_address_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_address_state, LinkAddressState);
 
-const char* link_online_state_to_string(LinkOnlineState s) _const_;
-LinkOnlineState link_online_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_online_state, LinkOnlineState);
 
 typedef struct LinkOperationalStateRange {
         LinkOperationalState min;
index f5d0632c23386b21409cbdf8c4f612f56b1a3d48..a3cc5c52d1495cf82b7bb81f89571029849c60a9 100644 (file)
@@ -77,10 +77,8 @@ int manager_handle_action(
                 bool is_edge,
                 const char *action_seat);
 
-const char* handle_action_verb_to_string(HandleAction h) _const_;
-
-const char* handle_action_to_string(HandleAction h) _const_;
-HandleAction handle_action_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(handle_action_verb, HandleAction);
+DECLARE_STRING_TABLE_LOOKUP(handle_action, HandleAction);
 
 const HandleActionData* handle_action_lookup(HandleAction action);
 
index e1a40cd93a0801d25964dfb3ea1791a8a5fc0776..1cb4ed460541e0e848353628de04615824967e37 100644 (file)
@@ -87,5 +87,4 @@ static inline bool inhibit_what_is_valid(InhibitWhat w) {
 const char* inhibit_what_to_string(InhibitWhat w);
 int inhibit_what_from_string(const char *s);
 
-const char* inhibit_mode_to_string(InhibitMode k);
-InhibitMode inhibit_mode_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(inhibit_mode, InhibitMode);
index 5f85003f7a3ce97761588cb5803b8b8af248cae1..d339006f17e784559175cdcbd056018439b11e85 100644 (file)
@@ -196,20 +196,15 @@ int session_kill(Session *s, KillWhom whom, int signo, sd_bus_error *error);
 
 SessionState session_get_state(Session *s);
 
-const char* session_state_to_string(SessionState t) _const_;
-SessionState session_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(session_state, SessionState);
 
-const char* session_type_to_string(SessionType t) _const_;
-SessionType session_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(session_type, SessionType);
 
-const char* session_class_to_string(SessionClass t) _const_;
-SessionClass session_class_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(session_class, SessionClass);
 
-const char* kill_whom_to_string(KillWhom k) _const_;
-KillWhom kill_whom_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
 
-const char* tty_validity_to_string(TTYValidity t) _const_;
-TTYValidity tty_validity_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(tty_validity, TTYValidity);
 
 void session_leave_vt(Session *s);
 
index 413cfb3f8e3019fb773fa003d9f0bfbb3805c8aa..b38af08744b23239183aee18feb15659b5d29e18 100644 (file)
@@ -83,10 +83,8 @@ int user_check_linger_file(const User *u);
 void user_elect_display(User *u);
 void user_update_last_session_timer(User *u);
 
-const char* user_state_to_string(UserState s) _const_;
-UserState user_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(user_state, UserState);
 
-const char* user_gc_mode_to_string(UserGCMode m) _const_;
-UserGCMode user_gc_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(user_gc_mode, UserGCMode);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_compat_user_tasks_max);
index 353cdd68281fa09be5a9db31bfbd6f9beb38c923..6a99b2bfbacba8090d1027e3517373f4fc333272 100644 (file)
@@ -10,8 +10,7 @@ typedef enum ImageCleanPoolMode {
         _IMAGE_CLEAN_POOL_INVALID = -EINVAL,
 } ImageCleanPoolMode;
 
-ImageCleanPoolMode image_clean_pool_mode_from_string(const char *s) _pure_;
-const char* image_clean_pool_mode_to_string(ImageCleanPoolMode mode) _const_;
+DECLARE_STRING_TABLE_LOOKUP(image_clean_pool_mode, ImageCleanPoolMode);
 
 int image_clean_pool_operation(Manager *manager, ImageCleanPoolMode mode, Operation **ret_operation);
 int clean_pool_read_first_entry(FILE *file, int child_error, sd_bus_error *error);
index b82a67d7032d189900fbff9da7193c526c949dbc..d02bb9a965edf0df41e82e7db6844a731e68bb91 100644 (file)
@@ -107,14 +107,11 @@ void machine_release_unit(Machine *m);
 
 MachineState machine_get_state(Machine *m);
 
-const char* machine_class_to_string(MachineClass t) _const_;
-MachineClass machine_class_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(machine_class, MachineClass);
 
-const char* machine_state_to_string(MachineState t) _const_;
-MachineState machine_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(machine_state, MachineState);
 
-const char* kill_whom_to_string(KillWhom k) _const_;
-KillWhom kill_whom_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
 
 int machine_openpt(Machine *m, int flags, char **ret_peer);
 int machine_start_getty(Machine *m, const char *ptmx_name, sd_bus_error *error);
@@ -149,8 +146,7 @@ typedef enum AcquireMetadata {
         _ACQUIRE_METADATA_INVALID = -EINVAL,
 } AcquireMetadata;
 
-AcquireMetadata acquire_metadata_from_string(const char *s) _pure_;
-const char* acquire_metadata_to_string(AcquireMetadata am) _const_;
+DECLARE_STRING_TABLE_LOOKUP(acquire_metadata, AcquireMetadata);
 inline static bool should_acquire_metadata(AcquireMetadata am) {
         return am == ACQUIRE_METADATA_YES || am == ACQUIRE_METADATA_GRACEFUL;
 }
index 9fcefbc291ee711776366073d00c47d3c96aca3f..829e767da0f0574a454c9b8b0e562367532fdc12 100644 (file)
@@ -2,8 +2,8 @@
  * Copyright Â© 2020 VMware, Inc. */
 #pragma once
 
-#include "shared-forward.h"
 #include "netdev.h"
+#include "shared-forward.h"
 
 typedef enum BareUDPProtocol {
         BARE_UDP_PROTOCOL_IPV4    = ETH_P_IP,
@@ -25,7 +25,6 @@ typedef struct BareUDP {
 DEFINE_NETDEV_CAST(BAREUDP, BareUDP);
 extern const NetDevVTable bare_udp_vtable;
 
-const char* bare_udp_protocol_to_string(BareUDPProtocol d) _const_;
-BareUDPProtocol bare_udp_protocol_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bare_udp_protocol, BareUDPProtocol);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_bare_udp_iftype);
index 4279c74517b2461c507d091b68fb00c6e4b1e8af..0bc48b482b265ad72bb26713640c63459644dd4d 100644 (file)
@@ -1,8 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "shared-forward.h"
 #include "netdev.h"
+#include "shared-forward.h"
 
 #define LINK_BRIDGE_PORT_PRIORITY_INVALID 128U
 #define LINK_BRIDGE_PORT_PRIORITY_MAX 63U
@@ -41,8 +41,7 @@ typedef enum MulticastRouter {
 DEFINE_NETDEV_CAST(BRIDGE, Bridge);
 extern const NetDevVTable bridge_vtable;
 
-const char* multicast_router_to_string(MulticastRouter i) _const_;
-MulticastRouter multicast_router_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(multicast_router, MulticastRouter);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_multicast_router);
 CONFIG_PARSER_PROTOTYPE(config_parse_bridge_igmp_version);
index a2cec0506ce4009f97a8c42fc43399005ba352fe..9c518b610d15025e29b2c39cb42560756ea473fb 100644 (file)
@@ -4,8 +4,8 @@
 #include <linux/fou.h>
 
 #include "in-addr-util.h"
-#include "shared-forward.h"
 #include "netdev.h"
+#include "shared-forward.h"
 
 typedef enum FooOverUDPEncapType {
         NETDEV_FOO_OVER_UDP_ENCAP_UNSPEC = FOU_ENCAP_UNSPEC,
@@ -34,8 +34,7 @@ typedef struct FouTunnel {
 DEFINE_NETDEV_CAST(FOU, FouTunnel);
 extern const NetDevVTable foutnl_vtable;
 
-const char* fou_encap_type_to_string(FooOverUDPEncapType d) _const_;
-FooOverUDPEncapType fou_encap_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(fou_encap_type, FooOverUDPEncapType);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_fou_encap_type);
 CONFIG_PARSER_PROTOTYPE(config_parse_fou_tunnel_address);
index d1f52a5d0b54af54be020469ca1defe3044ba3eb..3dcccb824351a98c6d3e0a39ebd9a9d531ca5140 100644 (file)
@@ -3,9 +3,9 @@
 
 #include <linux/if_link.h>
 
-#include "shared-forward.h"
 #include "in-addr-util.h"
 #include "netdev.h"
+#include "shared-forward.h"
 
 #define GENEVE_VID_MAX (1u << 24) - 1
 
@@ -44,8 +44,7 @@ typedef struct Geneve {
 DEFINE_NETDEV_CAST(GENEVE, Geneve);
 extern const NetDevVTable geneve_vtable;
 
-const char* geneve_df_to_string(GeneveDF d) _const_;
-GeneveDF geneve_df_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(geneve_df, GeneveDF);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_geneve_vni);
 CONFIG_PARSER_PROTOTYPE(config_parse_geneve_address);
index da3ef994a5930fb763c69e0be123afc7948b6ed1..3f0b37fe1487b298d6eae54492931f4ff9bef6e9 100644 (file)
@@ -23,6 +23,6 @@ typedef struct Hsr {
 DEFINE_NETDEV_CAST(HSR, Hsr);
 extern const NetDevVTable hsr_vtable;
 
-HsrProtocol hsr_protocol_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(hsr_protocol, HsrProtocol);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_hsr_protocol);
index 0f0be41cb94c760be303cde3786812801fde12f3..7eb23ff3ac6df7d0ab1fec8513fa5d02791cb4cd 100644 (file)
@@ -14,8 +14,7 @@ typedef enum NetDevLocalAddressType {
         _NETDEV_LOCAL_ADDRESS_TYPE_INVALID = -EINVAL,
 } NetDevLocalAddressType;
 
-const char* netdev_local_address_type_to_string(NetDevLocalAddressType t) _const_;
-NetDevLocalAddressType netdev_local_address_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(netdev_local_address_type, NetDevLocalAddressType);
 
 int link_get_local_address(
                 Link *link,
index 7b97c59af3c50ece65dd81ed2e67e1be64bd5ea8..afc252480c9e1aecf69ad5b3797235c5228164c6 100644 (file)
@@ -241,8 +241,7 @@ int netdev_generate_hw_addr(NetDev *netdev, Link *parent, const char *name,
 bool netdev_needs_reconfigure(NetDev *netdev, NetDevLocalAddressType type);
 int link_request_stacked_netdev(Link *link, NetDev *netdev);
 
-const char* netdev_kind_to_string(NetDevKind d) _const_;
-NetDevKind netdev_kind_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
 
 static inline NetDevCreateType netdev_get_create_type(NetDev *netdev) {
         assert(netdev);
index 7a517e8b2f8d247ebf7bba5f84efc57cc3759368..f7738f8783cfb6178e9d3733e5710973ea9e28dd 100644 (file)
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "shared-forward.h"
 #include "fou-tunnel.h"
 #include "netdev.h"
 #include "networkd-link.h"
+#include "shared-forward.h"
 
 /* For IFLA_IPTUN_PROTO attribute */
 typedef enum TunnelMode {
@@ -122,8 +122,7 @@ extern const NetDevVTable ip6gretap_vtable;
 extern const NetDevVTable ip6tnl_vtable;
 extern const NetDevVTable erspan_vtable;
 
-const char* tunnel_mode_to_string(TunnelMode d) _const_;
-TunnelMode tunnel_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(tunnel_mode, TunnelMode);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_mode);
 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_local_address);
index 5e6a5833ab77ddab5ae78d5cfc33cb7f18dd1376..90fc92e45aa1d61c86f67c0c05fc93898e82d1b9 100644 (file)
@@ -65,8 +65,7 @@ typedef struct VxLan {
 DEFINE_NETDEV_CAST(VXLAN, VxLan);
 extern const NetDevVTable vxlan_vtable;
 
-const char* df_to_string(VxLanDF d) _const_;
-VxLanDF df_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(df, VxLanDF);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_vxlan_address);
 CONFIG_PARSER_PROTOTYPE(config_parse_port_range);
index 693696e77e272075d91939ae377a0783c9624fa7..9eb9331923b9f2a86b2e18984755e8fecce99d54 100644 (file)
@@ -73,8 +73,7 @@ static inline bool in6_prefix_is_filtered(const struct in6_addr *prefix, uint8_t
 
 int link_get_captive_portal(Link *link, const char **ret);
 
-const char* dhcp_option_data_type_to_string(DHCPOptionDataType d) _const_;
-DHCPOptionDataType dhcp_option_data_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dhcp_option_data_type, DHCPOptionDataType);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_route_metric);
index 5ce5c2c97b96ed06720d7d180a67c7f976615594..451eadf3002109aaab1df5dad3d7f3ce1b2c692a 100644 (file)
@@ -26,5 +26,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_pd_prefix_hint);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_mud_url);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp6_client_start_mode);
 
-const char* dhcp6_client_start_mode_to_string(DHCP6ClientStartMode i) _const_;
-DHCP6ClientStartMode dhcp6_client_start_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dhcp6_client_start_mode, DHCP6ClientStartMode);
index 95d38c7c29767a0194c1b60a352d3b23a1412b14..2237f0b4623669cd5a117b6540d5d1d24935e132 100644 (file)
@@ -16,8 +16,7 @@ UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto);
 bool link_get_use_dns(Link *link, NetworkConfigSource proto);
 bool link_get_use_dnr(Link *link, NetworkConfigSource proto);
 
-const char* use_domains_to_string(UseDomains p) _const_;
-UseDomains use_domains_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(use_domains, UseDomains);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_domains);
 CONFIG_PARSER_PROTOTYPE(config_parse_dns);
index 88cde502f2486c3b98247947ae341c2ba61173af..62ce9d957ebd080c97a699a4a12c3c4aeec74d02 100644 (file)
@@ -24,7 +24,6 @@ int link_update_ipv6ll_addrgen_mode(Link *link, sd_netlink_message *message);
 int link_set_ipv6ll_stable_secret(Link *link);
 int link_set_ipv6ll_addrgen_mode(Link *link, IPv6LinkLocalAddressGenMode mode);
 
-const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
-IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
index e54c931e582c5fd4294ab4e1d0ad89eb47c34a77..845b6f211f9cb54df69bb6c6042c69fa6127d2a0 100644 (file)
@@ -235,8 +235,7 @@ bool link_has_ipv6_connectivity(Link *link);
 
 int link_stop_engines(Link *link, bool may_keep_dynamic);
 
-const char* link_state_to_string(LinkState s) _const_;
-LinkState link_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(link_state, LinkState);
 
 int link_request_stacked_netdevs(Link *link, NetDevLocalAddressType type);
 
@@ -251,8 +250,8 @@ int link_check_initialized(Link *link);
 int manager_udev_process_link(Manager *m, sd_device *device, sd_device_action_t action);
 int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
 
-int link_flags_to_string_alloc(uint32_t flags, char **ret);
-const char* kernel_operstate_to_string(int t) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(link_flags, uint32_t);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(kernel_operstate, int);
 
 void link_required_operstate_for_online(Link *link, LinkOperationalStateRange *ret);
 AddressFamily link_required_family_for_online(Link *link);
index d098616e4dcae252ba18146493755141ea6d9545..7bd8f1941ad0bc96d8897921520b83298e07f17f 100644 (file)
@@ -13,7 +13,6 @@ typedef enum LLDPMode {
 
 int link_lldp_rx_configure(Link *link);
 
-const char* lldp_mode_to_string(LLDPMode m) _const_;
-LLDPMode lldp_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(lldp_mode, LLDPMode);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_lldp_mode);
index 0efaf2b9fdcb15e20e07f8b64d367aba2c9f36db..b6534c9510af795d86dea9a98946041d79ee6b68 100644 (file)
@@ -442,8 +442,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
 
 const struct ConfigPerfItem* network_network_gperf_lookup(const char *str, GPERF_LEN_TYPE length);
 
-const char* keep_configuration_to_string(KeepConfiguration i) _const_;
-KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(keep_configuration, KeepConfiguration);
 
-const char* activation_policy_to_string(ActivationPolicy i) _const_;
-ActivationPolicy activation_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(activation_policy, ActivationPolicy);
index 34187de80a048185f273eab814bd086715194d0a..d656d7aa7aa8af3139643421f2b762962262ff0a 100644 (file)
@@ -150,7 +150,7 @@ static inline int link_queue_request(
 int manager_process_requests(Manager *manager);
 int request_call_netlink_async(sd_netlink *nl, sd_netlink_message *m, Request *req);
 
-const char* request_type_to_string(RequestType t) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(request_type, RequestType);
 
 typedef struct RemoveRequest RemoveRequest;
 typedef int (*remove_request_netlink_handler_t)(sd_netlink *nl, sd_netlink_message *m, RemoveRequest *req);
index 3c5fbb185ebef8ea025148163372ae706cc62a5f..cd62c9d1feab456015a5406d7fa3285a5aa0d880 100644 (file)
@@ -56,8 +56,7 @@ int radv_add_prefix(Link *link, const struct in6_addr *prefix, uint8_t prefix_le
 int link_request_radv(Link *link);
 int link_drop_radv_config(Link *link, Network *network);
 
-const char* radv_prefix_delegation_to_string(RADVPrefixDelegation i) _const_;
-RADVPrefixDelegation radv_prefix_delegation_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(radv_prefix_delegation, RADVPrefixDelegation);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_router_prefix_delegation);
 CONFIG_PARSER_PROTOTYPE(config_parse_router_lifetime);
index 0540bfbb4cbeba02afd2489d2c5852365014ac8d..2ed992511b652cfccf58a05034037fc6cc3d494e 100644 (file)
@@ -31,18 +31,17 @@ int manager_address_is_reachable(
                 const union in_addr_union *prefsrc, /* optional */
                 Address **ret);
 
-int route_type_from_string(const char *s) _pure_;
-const char* route_type_to_string(int t) _const_;
+DECLARE_STRING_TABLE_LOOKUP(route_type, int);
 
-int route_scope_from_string(const char *s);
-int route_scope_to_string_alloc(int t, char **ret);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(route_scope, int);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(route_scope, int);
 
-int route_protocol_from_string(const char *s);
-int route_protocol_to_string_alloc(int t, char **ret);
-int route_protocol_full_from_string(const char *s);
-int route_protocol_full_to_string_alloc(int t, char **ret);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(route_protocol, int);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(route_protocol, int);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(route_protocol_full, int);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(route_protocol_full, int);
 
-int route_flags_to_string_alloc(uint32_t flags, char **ret);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(route_flags, uint32_t);
 
 int manager_get_route_table_from_string(const Manager *m, const char *s, uint32_t *ret);
 int manager_get_route_table_to_string(const Manager *m, uint32_t table, bool append_num, char **ret);
index 1655273ed9582812f9f385c7901770d75059a7d5..6902bfbf234b65b3f1286a330e701166ee4e7260 100644 (file)
@@ -46,8 +46,7 @@ typedef struct RoutingPolicyRule {
         struct fib_rule_port_range dport; /* FRA_DPORT_RANGE */
 } RoutingPolicyRule;
 
-int fr_act_type_from_string(const char *s) _pure_;
-const char* fr_act_type_to_string(int t) _const_;
+DECLARE_STRING_TABLE_LOOKUP(fr_act_type, int);
 
 DECLARE_TRIVIAL_REF_UNREF_FUNC(RoutingPolicyRule, routing_policy_rule);
 
index 5cf8636312f4e90facc2c2da03f928391a51a231..54ca415410803d97095722d801c124becad853ae 100644 (file)
@@ -39,11 +39,9 @@ int link_set_sysctl(Link *link);
 int link_set_ipv6_mtu(Link *link, int log_level);
 int link_set_ipv6_mtu_async(Link *link);
 
-const char* ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) _const_;
-IPv6PrivacyExtensions ipv6_privacy_extensions_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ipv6_privacy_extensions, IPv6PrivacyExtensions);
 
-const char* ip_reverse_path_filter_to_string(IPReversePathFilter i) _const_;
-IPReversePathFilter ip_reverse_path_filter_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ip_reverse_path_filter, IPReversePathFilter);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_privacy_extensions);
 CONFIG_PARSER_PROTOTYPE(config_parse_ip_reverse_path_filter);
@@ -59,7 +57,6 @@ typedef enum IPv4ForceIgmpVersion {
         _IPV4_FORCE_IGMP_VERSION_INVALID = -EINVAL,
 } IPv4ForceIgmpVersion;
 
-const char* ipv4_force_igmp_version_to_string(IPv4ForceIgmpVersion i) _const_;
-IPv4ForceIgmpVersion ipv4_force_igmp_version_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ipv4_force_igmp_version, IPv4ForceIgmpVersion);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_ipv4_force_igmp_version);
index 22a04269d3ab7eeb30b56fec830a8f420d87b28f..16bfb599023ab509e0d74e13951c4aff8142f4e7 100644 (file)
@@ -47,10 +47,9 @@ CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family);
 CONFIG_PARSER_PROTOTYPE(config_parse_ip_masquerade);
 CONFIG_PARSER_PROTOTYPE(config_parse_mud_url);
 
-const char* network_config_source_to_string(NetworkConfigSource s) _const_;
-NetworkConfigSource network_config_source_from_string(const char* s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(network_config_source, NetworkConfigSource);
 
-int network_config_state_to_string_alloc(NetworkConfigState s, char **ret);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(network_config_state, NetworkConfigState);
 
 #define DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(type, name)               \
         static inline void name##_update_state(                         \
@@ -124,24 +123,19 @@ int network_config_state_to_string_alloc(NetworkConfigState s, char **ret);
                                     0);                                 \
         }
 
-const char* address_family_to_string(AddressFamily b) _const_;
-AddressFamily address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(address_family, AddressFamily);
 
-AddressFamily link_local_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(link_local_address_family, AddressFamily);
 
-const char* routing_policy_rule_address_family_to_string(AddressFamily b) _const_;
-AddressFamily routing_policy_rule_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(routing_policy_rule_address_family, AddressFamily);
 
-const char* nexthop_address_family_to_string(AddressFamily b) _const_;
-AddressFamily nexthop_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(nexthop_address_family, AddressFamily);
 
-const char* duplicate_address_detection_address_family_to_string(AddressFamily b) _const_;
-AddressFamily duplicate_address_detection_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family, AddressFamily);
 
-AddressFamily dhcp_deprecated_address_family_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_deprecated_address_family, AddressFamily);
 
-const char* dhcp_lease_server_type_to_string(sd_dhcp_lease_server_type_t t) _const_;
-sd_dhcp_lease_server_type_t dhcp_lease_server_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type_t);
 
 bool link_should_mark_config(Link *link, bool only_static, NetworkConfigSource source, uint8_t protocol);
 
index a677578cd8e4b439daeaf8891a568d56cf192efd..197c6e2f79a89d12675dbfa9f843af765ef6d86b 100644 (file)
@@ -6,9 +6,9 @@
 #include "capability-util.h"
 #include "conf-parser-forward.h"
 #include "cpu-set-util.h"
-#include "shared-forward.h"
 #include "rlimit-util.h"
 #include "seccomp-util.h"
+#include "shared-forward.h"
 #include "volatile-util.h"
 
 typedef struct CustomMount CustomMount;
@@ -277,17 +277,13 @@ CONFIG_PARSER_PROTOTYPE(config_parse_userns_ownership);
 CONFIG_PARSER_PROTOTYPE(config_parse_bind_user);
 CONFIG_PARSER_PROTOTYPE(config_parse_bind_user_shell);
 
-const char* resolv_conf_mode_to_string(ResolvConfMode a) _const_;
-ResolvConfMode resolv_conf_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(resolv_conf_mode, ResolvConfMode);
 
-const char* timezone_mode_to_string(TimezoneMode a) _const_;
-TimezoneMode timezone_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(timezone_mode, TimezoneMode);
 
-const char* console_mode_to_string(ConsoleMode m) _const_;
-ConsoleMode console_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(console_mode, ConsoleMode);
 
-const char* user_namespace_ownership_to_string(UserNamespaceOwnership a) _const_;
-UserNamespaceOwnership user_namespace_ownership_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(user_namespace_ownership, UserNamespaceOwnership);
 
 int parse_link_journal(const char *s, LinkJournal *ret_mode, bool *ret_try);
 
index 14814e740292654fe4237f91752c954eb741dd19..e42cf52c54cd2e9f9ab5eb5de98c754881d68fbb 100644 (file)
@@ -1,8 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "shared-forward.h"
 #include "runtime-scope.h"
+#include "shared-forward.h"
 #include "string-util.h"
 
 typedef struct PortableMetadata {
@@ -114,8 +114,6 @@ int portable_get_profiles(char ***ret);
 
 void portable_changes_free(PortableChange *changes, size_t n_changes);
 
-const char* portable_change_type_to_string(int t) _const_;
-int portable_change_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(portable_change_type, int);
 
-const char* portable_state_to_string(PortableState t) _const_;
-PortableState portable_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(portable_state, PortableState);
index 0139e7f7008dde464d465f5eee68e8d89b77868f..048b8b9f6a354cee9488bc101689d0b19c0ecf9b 100644 (file)
@@ -75,8 +75,6 @@ int dnssec_nsec_test(DnsAnswer *answer, DnsResourceKey *key, DnssecNsecResult *r
 
 int dnssec_test_positive_wildcard(DnsAnswer *a, const char *name, const char *source, const char *zone, bool *authenticated);
 
-const char* dnssec_result_to_string(DnssecResult m) _const_;
-DnssecResult dnssec_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dnssec_result, DnssecResult);
 
-const char* dnssec_verdict_to_string(DnssecVerdict m) _const_;
-DnssecVerdict dnssec_verdict_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dnssec_verdict, DnssecVerdict);
index b492d7d4bd32c9a10a40a486387d37f59855d4b0..1367f55242be52053fdff2873af19ad9a226c3f1 100644 (file)
@@ -125,5 +125,4 @@ int dns_scope_to_json(DnsScope *scope, bool with_cache, sd_json_variant **ret);
 int dns_type_suitable_for_protocol(uint16_t type, DnsProtocol protocol);
 int dns_question_types_suitable_for_protocol(DnsQuestion *q, DnsProtocol protocol);
 
-const char* dns_scope_origin_to_string(DnsScopeOrigin origin) _const_;
-DnsScopeOrigin dns_scope_origin_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_scope_origin, DnsScopeOrigin);
index 0752f228a9e3e188577b1cdec6ec238719fbc4cf..e3508313eba163d594ca1e58b8fa193d1a8cb15d 100644 (file)
@@ -16,8 +16,7 @@ typedef enum DnsServerType {
         _DNS_SERVER_TYPE_INVALID = -EINVAL,
 } DnsServerType;
 
-const char* dns_server_type_to_string(DnsServerType i) _const_;
-DnsServerType dns_server_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_server_type, DnsServerType);
 
 typedef enum DnsServerFeatureLevel {
         DNS_SERVER_FEATURE_LEVEL_TCP,
@@ -37,8 +36,7 @@ typedef enum DnsServerFeatureLevel {
 #define DNS_SERVER_FEATURE_LEVEL_IS_DNSSEC(x) ((x) >= DNS_SERVER_FEATURE_LEVEL_DO)
 #define DNS_SERVER_FEATURE_LEVEL_IS_UDP(x) IN_SET(x, DNS_SERVER_FEATURE_LEVEL_UDP, DNS_SERVER_FEATURE_LEVEL_EDNS0, DNS_SERVER_FEATURE_LEVEL_DO)
 
-const char* dns_server_feature_level_to_string(DnsServerFeatureLevel i) _const_;
-DnsServerFeatureLevel dns_server_feature_level_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_server_feature_level, DnsServerFeatureLevel);
 
 typedef struct DnsServer {
         Manager *manager;
index a7b0e41722085fee317c094e0ecd9ef56aa0b6e7..8904199b6366d014d44c828f59aac4912d280d95 100644 (file)
@@ -41,5 +41,4 @@ static inline uint16_t dns_stub_listener_extra_port(DnsStubListenerExtra *p) {
 void manager_dns_stub_stop(Manager *m);
 int manager_dns_stub_start(Manager *m);
 
-const char* dns_stub_listener_mode_to_string(DnsStubListenerMode p) _const_;
-DnsStubListenerMode dns_stub_listener_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_stub_listener_mode, DnsStubListenerMode);
index e7f9ca7fbf6d3353059653a85a43a0ec5631a81d..5912d986882581a5cbb24c9ad674c962e5d4045b 100644 (file)
@@ -178,8 +178,6 @@ static inline uint64_t dns_transaction_source_to_query_flags(DnsTransactionSourc
         }
 }
 
-const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
-DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_transaction_state, DnsTransactionState);
 
-const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
-DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_transaction_source, DnsTransactionSource);
index 6b3c91ed2880dc164c939aae27f631eec2f89d86..f4486207ef6e164259b035fe6af3cd912907ad63 100644 (file)
@@ -19,5 +19,4 @@ typedef enum ResolvConfMode {
 
 int resolv_conf_mode(void);
 
-const char* resolv_conf_mode_to_string(ResolvConfMode m) _const_;
-ResolvConfMode resolv_conf_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(resolv_conf_mode, ResolvConfMode);
index 49260d1dfa1022f3d0330506acca0640f99e5624..cf3f8e897e0ca7784e22e905b97881d502e913ac 100644 (file)
@@ -80,26 +80,18 @@ typedef enum BondPrimaryReselect {
         _NETDEV_BOND_PRIMARY_RESELECT_INVALID = -EINVAL,
 } BondPrimaryReselect;
 
-const char* bond_mode_to_string(BondMode d) _const_;
-BondMode bond_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_mode, BondMode);
 
-const char* bond_xmit_hash_policy_to_string(BondXmitHashPolicy d) _const_;
-BondXmitHashPolicy bond_xmit_hash_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_xmit_hash_policy, BondXmitHashPolicy);
 
-const char* bond_lacp_rate_to_string(BondLacpRate d) _const_;
-BondLacpRate bond_lacp_rate_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_lacp_rate, BondLacpRate);
 
-const char* bond_fail_over_mac_to_string(BondFailOverMac d) _const_;
-BondFailOverMac bond_fail_over_mac_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_fail_over_mac, BondFailOverMac);
 
-const char* bond_ad_select_to_string(BondAdSelect d) _const_;
-BondAdSelect bond_ad_select_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_ad_select, BondAdSelect);
 
-const char* bond_arp_validate_to_string(BondArpValidate d) _const_;
-BondArpValidate bond_arp_validate_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_arp_validate, BondArpValidate);
 
-const char* bond_arp_all_targets_to_string(BondArpAllTargets d) _const_;
-BondArpAllTargets bond_arp_all_targets_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_arp_all_targets, BondArpAllTargets);
 
-const char* bond_primary_reselect_to_string(BondPrimaryReselect d) _const_;
-BondPrimaryReselect bond_primary_reselect_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bond_primary_reselect, BondPrimaryReselect);
index 41f8a09faf507e90d25c1e2ac30682a84df30a64..84ea69a096aaf3ebe7b4737d982f9fc244a0037b 100644 (file)
@@ -34,4 +34,4 @@ int boot_entry_token_ensure_at(
 
 int parse_boot_entry_token_type(const char *s, BootEntryTokenType *type, char **token);
 
-const char* boot_entry_token_type_to_string(BootEntryTokenType t);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_token_type, BootEntryTokenType);
index a62a3f0b4ef8cb05e50b4385aabd8641a391ec4f..3bd516c75dfdc87df3614b03d532028970e39a3d 100644 (file)
@@ -96,12 +96,11 @@ typedef struct BootConfig {
                 .selected_entry = -1, \
         }
 
-const char* boot_entry_type_description_to_string(BootEntryType) _const_;
-const char* boot_entry_type_to_string(BootEntryType) _const_;
-BootEntryType boot_entry_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type_description, BootEntryType);
+DECLARE_STRING_TABLE_LOOKUP(boot_entry_type, BootEntryType);
 
-const char* boot_entry_source_description_to_string(BootEntrySource) _const_;
-const char* boot_entry_source_to_string(BootEntrySource) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source_description, BootEntrySource);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_source, BootEntrySource);
 
 BootEntry* boot_config_find_entry(BootConfig *config, const char *id);
 
index 171faa99804feec5cec2ba22b8f8763ad9dde7c1..cf7fbcd6a5c4b5208ddd4b06c0f3e48cb211e3df 100644 (file)
@@ -52,7 +52,6 @@ int bpf_map_new(const char *name, enum bpf_map_type type, size_t key_size, size_
 int bpf_map_update_element(int fd, const void *key, void *value);
 int bpf_map_lookup_element(int fd, const void *key, void *value);
 
-int bpf_cgroup_attach_type_from_string(const char *str) _pure_;
-const char* bpf_cgroup_attach_type_to_string(int attach_type) _const_;
+DECLARE_STRING_TABLE_LOOKUP(bpf_cgroup_attach_type, int);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(BPFProgram*, bpf_program_free);
index a166c97d35dd6852bc1d85ea98883a34dca214f3..ff865af9e4495b09ab46a210cb2a88bede713af6 100644 (file)
@@ -15,5 +15,4 @@ typedef enum BridgeState {
         _NETDEV_BRIDGE_STATE_INVALID   = -EINVAL,
 } BridgeState;
 
-const char* bridge_state_to_string(BridgeState d) _const_;
-BridgeState bridge_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(bridge_state, BridgeState);
index 88095be27e540ba622109ab7f907a6ebe85565b1..a50cfbc37b05d2b3aa5ea81c72664a97c017a317 100644 (file)
@@ -11,7 +11,7 @@ typedef enum ExecDirectoryFlags {
         _EXEC_DIRECTORY_FLAGS_INVALID = -EINVAL,
 } ExecDirectoryFlags;
 
-ExecDirectoryFlags exec_directory_flags_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(exec_directory_flags, ExecDirectoryFlags);
 
 typedef struct UnitInfo {
         const char *machine;
index cbaf7b2d7cf1e372fa923a12e8f355481d27bd90..a74619fb2f8b7d83cc9bcc68265cb3c366c1ee8b 100644 (file)
@@ -72,4 +72,4 @@ int bus_query_sender_pidref(sd_bus_message *m, PidRef *ret);
 
 int bus_get_instance_id(sd_bus *bus, sd_id128_t *ret);
 
-const char* bus_transport_to_string(BusTransport transport) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(bus_transport, BusTransport);
index df96ade91ea4105feab087eeb7ac1c36a3e1f4e2..ec17cbe39765a9348cac43383b3df7bb33757b9a 100644 (file)
@@ -87,16 +87,13 @@ bool condition_test_list(Condition *first, char **env, condition_to_string_t to_
 void condition_dump(Condition *c, FILE *f, const char *prefix, condition_to_string_t to_string);
 void condition_dump_list(Condition *first, FILE *f, const char *prefix, condition_to_string_t to_string);
 
-const char* condition_type_to_string(ConditionType t) _const_;
-ConditionType condition_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(condition_type, ConditionType);
 void condition_types_list(void);
 
-const char* assert_type_to_string(ConditionType t) _const_;
-ConditionType assert_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(assert_type, ConditionType);
 void assert_types_list(void);
 
-const char* condition_result_to_string(ConditionResult r) _const_;
-ConditionResult condition_result_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(condition_result, ConditionResult);
 
 static inline bool condition_takes_path(ConditionType t) {
         return IN_SET(t,
index 77010d2779e482b5495a4f164f5527368d4737f9..0839e4894c9d4a1c64d7e9ba19cccd59c1b49e42 100644 (file)
@@ -34,8 +34,7 @@ typedef enum SuidDumpMode {
 
 int set_dumpable(SuidDumpMode mode);
 
-const char* coredump_filter_to_string(CoredumpFilter i) _const_;
-CoredumpFilter coredump_filter_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(coredump_filter, CoredumpFilter);
 int coredump_filter_mask_from_string(const char *s, uint64_t *ret);
 
 int parse_auxv(int log_level,
index 30c399dea6fc6fb25cf208e73f87e621c9882412..728e447cdd19a43d37fe27e72170881e2087d84a 100644 (file)
@@ -59,8 +59,7 @@ int image_rename(Image *i, const char *new_name, RuntimeScope scope);
 int image_clone(Image *i, const char *new_name, bool read_only, RuntimeScope scope);
 int image_read_only(Image *i, bool b, RuntimeScope scope);
 
-const char* image_type_to_string(ImageType t) _const_;
-ImageType image_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(image_type, ImageType);
 
 int image_path_lock(RuntimeScope scope, const char *path, int operation, LockFile *global, LockFile *local);
 int image_name_lock(RuntimeScope scope, const char *name, int operation, LockFile *ret);
index bb413f1b962752d697da9cc77cf197fec8eeeac0..e36d91a0b47cd1a5b7370e84db5c7df2a198e4b3 100644 (file)
@@ -308,17 +308,15 @@ enum {
         _DNS_EDE_RCODE_INVALID               = -EINVAL,
 };
 
-const char* dns_rcode_to_string(int i) _const_;
-int dns_rcode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_rcode, int);
 const char* format_dns_rcode(int i, char buf[static DECIMAL_STR_MAX(int)]);
 #define FORMAT_DNS_RCODE(i) format_dns_rcode(i, (char [DECIMAL_STR_MAX(int)]) {})
 
-const char* dns_ede_rcode_to_string(int i) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(dns_ede_rcode, int);
 const char* format_dns_ede_rcode(int i, char buf[static DECIMAL_STR_MAX(int)]);
 #define FORMAT_DNS_EDE_RCODE(i) format_dns_ede_rcode(i, (char [DECIMAL_STR_MAX(int)]) {})
 
-const char* dns_protocol_to_string(DnsProtocol p) _const_;
-DnsProtocol dns_protocol_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_protocol, DnsProtocol);
 
 #define LLMNR_MULTICAST_IPV4_ADDRESS ((struct in_addr) { .s_addr = htobe32(224U << 24 | 252U) })
 #define LLMNR_MULTICAST_IPV6_ADDRESS ((struct in6_addr) { .s6_addr = { 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03 } })
@@ -343,7 +341,7 @@ enum {
         DNS_SVC_PARAM_KEY_INVALID         = 65535 /* RFC 9460 */
 };
 
-const char* dns_svc_param_key_to_string(int i) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(dns_svc_param_key, int);
 const char* format_dns_svc_param_key(uint16_t i, char buf[static DECIMAL_STR_MAX(uint16_t)+3]);
 #define FORMAT_DNS_SVC_PARAM_KEY(i) format_dns_svc_param_key(i, (char [DECIMAL_STR_MAX(uint16_t)+3]) {})
 
index 4f3686878b34b3aef7b77d18a24eb6e7c6576c21..c30cd71cfa5c7347830a1c62d3b591fd2d2f89f0 100644 (file)
@@ -431,16 +431,12 @@ extern const struct hash_ops dns_resource_key_hash_ops;
 extern const struct hash_ops dns_resource_record_hash_ops;
 extern const struct hash_ops dns_resource_record_hash_ops_by_key;
 
-int dnssec_algorithm_to_string_alloc(int i, char **ret);
-int dnssec_algorithm_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_algorithm, int);
 
-int dnssec_digest_to_string_alloc(int i, char **ret);
-int dnssec_digest_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_digest, int);
 
-int sshfp_algorithm_to_string_alloc(int i, char **ret);
-int sshfp_algorithm_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sshfp_algorithm, int);
 
-int sshfp_key_type_to_string_alloc(int i, char **ret);
-int sshfp_key_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sshfp_key_type, int);
 
 int dns_json_dispatch_resource_key(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
index 2bb7a8b4482a2e1453f58d9d16afdaf93187edf6..dc96d5961d705534ae1372c7c1cdf29857293b3b 100644 (file)
@@ -143,20 +143,19 @@ bool dns_class_is_pseudo(uint16_t class);
 bool dns_class_is_valid_rr(uint16_t class);
 
 /* TYPE?? follows http://tools.ietf.org/html/rfc3597#section-5 */
-const char* dns_type_to_string(int type);
-int dns_type_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(dns_type, int);
 
-const char* dns_class_to_string(uint16_t class);
-int dns_class_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(dns_class, uint16_t);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(dns_class, int);
 
 /* https://tools.ietf.org/html/draft-ietf-dane-protocol-23#section-7.2 */
-const char* tlsa_cert_usage_to_string(uint8_t cert_usage);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(tlsa_cert_usage, uint8_t);
 
 /* https://tools.ietf.org/html/draft-ietf-dane-protocol-23#section-7.3 */
-const char* tlsa_selector_to_string(uint8_t selector);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(tlsa_selector, uint8_t);
 
 /* https://tools.ietf.org/html/draft-ietf-dane-protocol-23#section-7.4 */
-const char* tlsa_matching_type_to_string(uint8_t selector);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(tlsa_matching_type, uint8_t);
 
 /* https://tools.ietf.org/html/rfc6844#section-5.1 */
 #define CAA_FLAG_CRITICAL (1u << 7)
index 2ce19f0eba76a3e2b7c5dedac3a4eb3fa49f3134..dbb8875997d08179b897b358fd0b08fa4561e1e6 100644 (file)
@@ -172,18 +172,15 @@ int ethtool_set_eee_settings(
                 usec_t tx_lpi_timer_usec,
                 uint32_t advertise);
 
-const char* duplex_to_string(Duplex d) _const_;
-Duplex duplex_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(duplex, Duplex);
 
-int wol_options_to_string_alloc(uint32_t opts, char **ret);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(wol_options, uint32_t);
 
-const char* port_to_string(NetDevPort port) _const_;
-NetDevPort port_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(port, NetDevPort);
 
-const char* mdi_to_string(int mdi) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(mdi, int);
 
-const char* ethtool_link_mode_bit_to_string(enum ethtool_link_mode_bit_indices val) _const_;
-enum ethtool_link_mode_bit_indices ethtool_link_mode_bit_from_string(const char *str) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ethtool_link_mode_bit, enum ethtool_link_mode_bit_indices);
 
 CONFIG_PARSER_PROTOTYPE(config_parse_duplex);
 CONFIG_PARSER_PROTOTYPE(config_parse_wol);
index 245b7773f4bdb41ba3aa7fc58aadb21cdccc5ebb..1c50f5a8367a2c5fba8fd6ddd83e2a448fbfc1f7 100644 (file)
@@ -56,8 +56,7 @@ typedef enum ExecCommandFlags {
 int exec_command_flags_from_strv(char * const *ex_opts, ExecCommandFlags *ret);
 int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ret);
 
-const char* exec_command_flags_to_string(ExecCommandFlags i);
-ExecCommandFlags exec_command_flags_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP(exec_command_flags, ExecCommandFlags);
 
 int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]);
 
index 27b8d4664a0f39ce9e495ad19835b09ee8e354ae..4c656c109f196c02790028bd8446468e0c41daeb 100644 (file)
@@ -89,7 +89,7 @@ typedef struct ExitStatusSet {
 
 const char* exit_status_to_string(int code, ExitStatusClass class) _const_;
 const char* exit_status_class(int code) _const_;
-int exit_status_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(exit_status, int);
 
 typedef struct ExitStatusMapping {
         const char *name;
index 262c951502660577a974972a809e31f6b936f93b..6a3b24fc21e9ff42f0005f3bdfb56ff0034f06b1 100644 (file)
@@ -17,5 +17,4 @@ typedef enum FactoryResetMode {
 
 FactoryResetMode factory_reset_mode(void);
 
-const char* factory_reset_mode_to_string(FactoryResetMode) _const_;
-FactoryResetMode factory_reset_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(factory_reset_mode, FactoryResetMode);
index ee28aead8e9e24e4811b3a5ea64135884897a2c0..202e5407b47556d410b6f80dd6832d903b419e49 100644 (file)
@@ -47,11 +47,9 @@ typedef struct NFTSetContext {
 void nft_set_context_clear(NFTSetContext *s);
 int nft_set_context_dup(const NFTSetContext *src, NFTSetContext *dst);
 
-const char* nfproto_to_string(int i) _const_;
-int nfproto_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(nfproto, int);
 
-const char* nft_set_source_to_string(int i) _const_;
-int nft_set_source_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(nft_set_source, int);
 
 int nft_set_element_modify_iprange(
                 sd_netlink *nfnl,
index 5d6ee87ea14f715797fe82e942d4af03df04e1a4..c21a1f6905b94e3f991d196367b950587810aff4 100644 (file)
@@ -13,5 +13,4 @@ typedef enum GeneveDF {
         _NETDEV_GENEVE_DF_INVALID = -EINVAL,
 } GeneveDF;
 
-const char* geneve_df_to_string(GeneveDF d) _const_;
-GeneveDF geneve_df_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(geneve_df, GeneveDF);
index 7a977ac7bebac251ea9a204e5403856caeaafbe5..f59f2da29fdcb6aac1baf21c61c8ab0abc925623 100644 (file)
@@ -49,12 +49,11 @@ static inline bool partition_designator_is_verity(PartitionDesignator d) {
         return partition_verity_to_data(d) >= 0;
 }
 
-const char* partition_designator_to_string(PartitionDesignator d) _const_;
-PartitionDesignator partition_designator_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator);
 
-const char* partition_mountpoint_to_string(PartitionDesignator d) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(partition_mountpoint, PartitionDesignator);
 
-const char* gpt_partition_type_uuid_to_string(sd_id128_t id) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(gpt_partition_type_uuid, sd_id128_t);
 const char* gpt_partition_type_uuid_to_string_harder(
                 sd_id128_t id,
                 char buffer[static SD_ID128_UUID_STRING_MAX]);
index 7f6216ce6eb5dc4adb97d2a675c2399c1794b627..ee1c932d284800d583760700cc106434ff8b2865 100644 (file)
@@ -10,8 +10,7 @@ typedef enum HostnameSource {
         _HOSTNAME_INVALID = -EINVAL,
 } HostnameSource;
 
-const char* hostname_source_to_string(HostnameSource source) _const_;
-HostnameSource hostname_source_from_string(const char *str) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(hostname_source, HostnameSource);
 
 int sethostname_idempotent(const char *s);
 
index 9621cd884d3f40a5b4b92b90ee544d475ed1f075..2a594e1e6143bac6c4f8aa7e3c553f30fa4eb561 100644 (file)
@@ -30,11 +30,9 @@ static inline int import_url_append_component(const char *url, const char *suffi
         return import_url_change_suffix(url, 0, suffix, ret);
 }
 
-const char* import_type_to_string(ImportType v) _const_;
-ImportType import_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(import_type, ImportType);
 
-const char* import_verify_to_string(ImportVerify v) _const_;
-ImportVerify import_verify_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(import_verify, ImportVerify);
 
 int tar_strip_suffixes(const char *name, char **ret);
 int raw_strip_suffixes(const char *name, char **ret);
index 53753a0366bcb444badb2813029c4e28d06e7540..aa2e7c7f59e61d138269516e4893bdcb689bf7b2 100644 (file)
@@ -1,8 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "shared-forward.h"
 #include "runtime-scope.h"
+#include "shared-forward.h"
 #include "unit-file.h"
 
 typedef enum UnitFilePresetMode {
@@ -224,17 +224,14 @@ typedef enum PresetAction {
         _PRESET_ACTION_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */
 } PresetAction;
 
-const char* preset_action_past_tense_to_string(PresetAction action);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(preset_action_past_tense, PresetAction);
 
 void unit_file_presets_done(UnitFilePresets *p);
 PresetAction unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached);
 
-const char* unit_file_state_to_string(UnitFileState s) _const_;
-UnitFileState unit_file_state_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
 /* from_string conversion is unreliable because of the overlap between -EPERM and -1 for error. */
 
-const char* install_change_type_to_string(InstallChangeType t) _const_;
-InstallChangeType install_change_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(install_change_type, InstallChangeType);
 
-const char* unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
-UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(unit_file_preset_mode, UnitFilePresetMode);
index e50110729be6065e0023ee5c7c8ce3f460b275fc..6102294099bbeaa60c56dd7bf52dd5072690ae56 100644 (file)
@@ -17,8 +17,7 @@ static inline int ioprio_prio_value(int class, int data) {
         return IOPRIO_PRIO_VALUE_HINT(class, IOPRIO_PRIO_LEVEL(data), IOPRIO_PRIO_HINT(data));
 }
 
-int ioprio_class_to_string_alloc(int i, char **ret);
-int ioprio_class_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int);
 
 static inline bool ioprio_class_is_valid(int i) {
         return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
index cf7f89da39c1836ef2a8e7bd374ec5e86efade83..4cb74f3dcbb920529f7e096f2996c827dc13fca2 100644 (file)
@@ -21,8 +21,6 @@ typedef enum IPVlanFlags {
         _NETDEV_IPVLAN_FLAGS_INVALID = -EINVAL,
 } IPVlanFlags;
 
-const char* ipvlan_mode_to_string(IPVlanMode d) _const_;
-IPVlanMode ipvlan_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ipvlan_mode, IPVlanMode);
 
-const char* ipvlan_flags_to_string(IPVlanFlags d) _const_;
-IPVlanFlags ipvlan_flags_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(ipvlan_flags, IPVlanFlags);
index b9f7cf353d3e22c17a17612ed4681ba5d36ec5a6..85a3308986c5c78c58e664d1ba60f004381ecbf3 100644 (file)
@@ -12,7 +12,7 @@ typedef enum KernelImageType {
         _KERNEL_IMAGE_TYPE_INVALID = -EINVAL,
 } KernelImageType;
 
-const char* kernel_image_type_to_string(KernelImageType t) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(kernel_image_type, KernelImageType);
 
 int inspect_kernel(
                 int dir_fd,
index 5eccd63049231d41ab632197d552e470407035b7..6ffc93ebf4e1316c6c8fd4c53f7aa8d15025bf20 100644 (file)
@@ -15,5 +15,4 @@ typedef enum MacVlanMode {
         _NETDEV_MACVLAN_MODE_INVALID = -EINVAL,
 } MacVlanMode;
 
-const char* macvlan_mode_to_string(MacVlanMode d) _const_;
-MacVlanMode macvlan_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
index a25b707b1c95e87dda85b8295ce657c68cb88d61..c13d7649c9ef31199dd2224ae015e3d0a104a482 100644 (file)
@@ -97,11 +97,9 @@ typedef enum NamePolicy {
         _NAMEPOLICY_INVALID = -EINVAL,
 } NamePolicy;
 
-const char* name_policy_to_string(NamePolicy p) _const_;
-NamePolicy name_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(name_policy, NamePolicy);
 
-const char* alternative_names_policy_to_string(NamePolicy p) _const_;
-NamePolicy alternative_names_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(alternative_names_policy, NamePolicy);
 
 int device_get_sysattr_int_filtered(sd_device *device, const char *sysattr, int *ret_value);
 int device_get_sysattr_unsigned_filtered(sd_device *device, const char *sysattr, unsigned *ret_value);
index 891496ffebbb634535c317562cf291ff4004309a..cd2befc634084bc051530c16f9945da20461d109 100644 (file)
@@ -41,7 +41,7 @@ typedef struct SRIOV {
         struct ether_addr mac;
 } SRIOV;
 
-const char* sr_iov_attribute_to_string(SRIOVAttribute a) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(sr_iov_attribute, SRIOVAttribute);
 
 void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state);
 int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2);
index 2966aa08db0d915cac07654ae282b2bee39c633c..c684dea803eca366694e2de979ae97925f40093f 100644 (file)
@@ -33,5 +33,4 @@ int numa_to_cpu_set(const NUMAPolicy *policy, CPUSet *ret);
 
 int numa_mask_add_all(CPUSet *mask);
 
-const char* mpol_to_string(int i) _const_;
-int mpol_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(mpol, int);
index 0d1acaa0e295e9159158969eaa31254003f3892a..7fa30997f8553b7f56cf3d0eb255b87d55cecd22 100644 (file)
@@ -34,5 +34,4 @@ static inline void open_file_free_many(OpenFile **head) {
         LIST_CLEAR(open_files, *ASSERT_PTR(head), open_file_free);
 }
 
-const char* open_file_flags_to_string(OpenFileFlag t) _const_;
-OpenFileFlag open_file_flags_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(open_file_flags, OpenFileFlag);
index c700f6ca5d8dcface54572e9b0cdd330abcbde80..15f85117575a8fa3a35fd3c5a5d7c2a0d1acef66 100644 (file)
@@ -53,5 +53,4 @@ typedef enum OutputFlags {
 
 sd_json_format_flags_t output_mode_to_json_format_flags(OutputMode m);
 
-const char* output_mode_to_string(OutputMode m) _const_;
-OutputMode output_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(output_mode, OutputMode);
index 102644054bc0c01e322733939fe55858fb305ffa..d8f1ce636512ae28db78b68eda0ee9a6f8dd41f5 100644 (file)
@@ -68,19 +68,15 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_mode);
 CONFIG_PARSER_PROTOTYPE(config_parse_dns_over_tls_mode);
 CONFIG_PARSER_PROTOTYPE(config_parse_dns_cache_mode);
 
-const char* resolve_support_to_string(ResolveSupport p) _const_;
-ResolveSupport resolve_support_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(resolve_support, ResolveSupport);
 
-const char* dnssec_mode_to_string(DnssecMode p) _const_;
-DnssecMode dnssec_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dnssec_mode, DnssecMode);
 
-const char* dns_over_tls_mode_to_string(DnsOverTlsMode p) _const_;
-DnsOverTlsMode dns_over_tls_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_over_tls_mode, DnsOverTlsMode);
 
 bool dns_server_address_valid(int family, const union in_addr_union *sa);
 
-const char* dns_cache_mode_to_string(DnsCacheMode p) _const_;
-DnsCacheMode dns_cache_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(dns_cache_mode, DnsCacheMode);
 
 /* A resolv.conf file containing the DNS server and domain data we learnt from uplink, i.e. the full uplink data */
 #define PRIVATE_UPLINK_RESOLV_CONF "/run/systemd/resolve/resolv.conf"
index 84ba1a2f8a1eecf9772403b8945e70aee52a77d3..871135c85be41edffcad483daadc572cddb81b9d 100644 (file)
@@ -25,7 +25,7 @@ extern DLSYM_PROTOTYPE(seccomp_syscall_resolve_num_arch);
 
 int dlopen_libseccomp(void);
 
-const char* seccomp_arch_to_string(uint32_t c);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(seccomp_arch, uint32_t);
 int seccomp_arch_from_string(const char *n, uint32_t *ret);
 
 int seccomp_init_for_arch(scmp_filter_ctx *ret, uint32_t arch, uint32_t default_action);
@@ -180,4 +180,4 @@ enum {
 
 bool seccomp_errno_or_action_is_valid(int n) _const_;
 int seccomp_parse_errno_or_action(const char *p) _pure_;
-const char* seccomp_errno_or_action_to_string(int num) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(seccomp_errno_or_action, int);
index 6251fb7922f0a719aa5ad3be3496dbf3c80411d1..90debea14770f0962ba45d364f64e4a1c95fa676 100644 (file)
@@ -6,8 +6,7 @@
 #include "shared-forward.h"
 
 int secure_bits_to_strv(int i, char ***ret);
-int secure_bits_to_string_alloc(int i, char **ret);
-int secure_bits_from_string(const char *s);
+DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(secure_bits, int);
 
 static inline bool secure_bits_is_valid(int i) {
         return ((SECURE_ALL_BITS | SECURE_ALL_LOCKS) & i) == i;
index 984a1c53dd23a013eef81d2a65973bb90a66d38d..ea4856a70ca0285b4e10ba68d0446c13f2dbd5b5 100644 (file)
@@ -17,8 +17,7 @@ typedef enum SleepOperation {
         _SLEEP_OPERATION_INVALID = -EINVAL,
 } SleepOperation;
 
-const char* sleep_operation_to_string(SleepOperation s) _const_;
-SleepOperation sleep_operation_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(sleep_operation, SleepOperation);
 
 static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation) {
         return IN_SET(operation, SLEEP_HIBERNATE, SLEEP_HYBRID_SLEEP);
index c6fb8c3d2a8d66511f205f806336f4815d97862a..48a500c081830ebe550c516e60c2c7266ed4bd83 100644 (file)
@@ -11,9 +11,8 @@ typedef enum SocketAddressBindIPv6Only {
         _SOCKET_ADDRESS_BIND_IPV6_ONLY_INVALID = -EINVAL,
 } SocketAddressBindIPv6Only;
 
-const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b) _const_;
-SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s) _pure_;
-SocketAddressBindIPv6Only socket_address_bind_ipv6_only_or_bool_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
+DECLARE_STRING_TABLE_LOOKUP_FROM_STRING(socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only);
 
 int socket_address_listen(
                 const SocketAddress *a,
index a357016149ef3a4732b8ba7d2086cd19c615fe0a..81600d597664e63c6563ef89a0b45a1f676769ec 100644 (file)
@@ -54,7 +54,7 @@
 #define LOAD_OPTIONS_EVENT_TAG_ID UINT32_C(0x8F3B22ED)
 #endif
 
-const char* tpm2_log_event_type_to_string(uint32_t type) _const_;
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(tpm2_log_event_type, uint32_t);
 
 #if HAVE_TPM2
 
index 4600512db866eeb275a603313662162df259b25e..1dc3326b3001fc3cb593096c52e355faaf0948dd 100644 (file)
@@ -2,8 +2,8 @@
 #pragma once
 
 #include "bitfield.h"
-#include "shared-forward.h"
 #include "openssl-util.h"
+#include "shared-forward.h"
 
 typedef enum TPM2Flags {
         TPM2_FLAGS_USE_PIN     = 1 << 0,
@@ -149,8 +149,7 @@ typedef enum Tpm2UserspaceEventType {
         _TPM2_USERSPACE_EVENT_TYPE_INVALID = -EINVAL,
 } Tpm2UserspaceEventType;
 
-const char* tpm2_userspace_event_type_to_string(Tpm2UserspaceEventType type) _const_;
-Tpm2UserspaceEventType tpm2_userspace_event_type_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(tpm2_userspace_event_type, Tpm2UserspaceEventType);
 
 int tpm2_pcr_extend_bytes(Tpm2Context *c, char **banks, unsigned pcr_index, const struct iovec *data, const struct iovec *secret, Tpm2UserspaceEventType event, const char *description);
 int tpm2_nvpcr_get_index(const char *name, uint32_t *ret);
@@ -508,8 +507,7 @@ enum {
         _TPM2_PCR_INDEX_INVALID     = -EINVAL,
 };
 
-int tpm2_pcr_index_from_string(const char *s) _pure_;
-const char* tpm2_pcr_index_to_string(int pcr) _const_;
+DECLARE_STRING_TABLE_LOOKUP(tpm2_pcr_index, int);
 
 /* The first and last NV index handle that is not registered to any company, as per TCG's "Registry of
  * Reserved TPM 2.0 Handles and Localities", section 2.2.2. */
index b98b59f3ff95e991b2265516df65ad2678a47899..c3d52d2bd71aa2768f2e8e32288de4badfed214c 100644 (file)
@@ -545,11 +545,8 @@ bool user_record_matches_user_name(const UserRecord *u, const char *username);
 
 int json_dispatch_dispositions_mask(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata);
 
-const char* user_storage_to_string(UserStorage t) _const_;
-UserStorage user_storage_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(user_storage, UserStorage);
 
-const char* user_disposition_to_string(UserDisposition t) _const_;
-UserDisposition user_disposition_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(user_disposition, UserDisposition);
 
-const char* auto_resize_mode_to_string(AutoResizeMode m) _const_;
-AutoResizeMode auto_resize_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(auto_resize_mode, AutoResizeMode);
index fd9c323fae163c58cd70b216e908d9ba77829679..3035ad2ef437c3c48f8070101def4e2bd7ee864c 100644 (file)
@@ -12,7 +12,6 @@ typedef enum VolatileMode {
         _VOLATILE_MODE_INVALID = -EINVAL,
 } VolatileMode;
 
-VolatileMode volatile_mode_from_string(const char *s);
-const char* volatile_mode_to_string(VolatileMode m);
+DECLARE_STRING_TABLE_LOOKUP(volatile_mode, VolatileMode);
 
 int query_volatile_mode(VolatileMode *ret);
index f590dfffa17ff06a3b08293430ebb2931520711a..e6b52ab0aed1bdbf1d6bf510e89938390084cbf6 100644 (file)
@@ -9,6 +9,5 @@
 int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_iftype, char **ret_ssid);
 int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *ret_bssid);
 
-const char* nl80211_iftype_to_string(enum nl80211_iftype iftype) _const_;
-enum nl80211_iftype nl80211_iftype_from_string(const char *s) _pure_;
-const char* nl80211_cmd_to_string(int cmd) _const_;
+DECLARE_STRING_TABLE_LOOKUP(nl80211_iftype, enum nl80211_iftype);
+DECLARE_STRING_TABLE_LOOKUP_TO_STRING(nl80211_cmd, int);
index afaca79f5f63ab42e8f2287d2a904a5f49adcdea..4e3fd54110f15f67164d8a6b651ab009c5131762 100644 (file)
@@ -95,8 +95,5 @@ Instance* resource_find_instance(Resource *rr, const char *version);
 
 int resource_resolve_path(Resource *rr, const char *root, const char *relative_to_directory, const char *node);
 
-ResourceType resource_type_from_string(const char *s) _pure_;
-const char* resource_type_to_string(ResourceType t) _const_;
-
-PathRelativeTo path_relative_to_from_string(const char *s) _pure_;
-const char* path_relative_to_to_string(PathRelativeTo r) _const_;
+DECLARE_STRING_TABLE_LOOKUP(resource_type, ResourceType);
+DECLARE_STRING_TABLE_LOOKUP(path_relative_to, PathRelativeTo);
index ce6016794b3f3baac0a25c00c36ce9f522297430..e00327c01526bbef1ba43290f3c7ea2b6d172f65 100644 (file)
@@ -135,8 +135,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
 int link_get_config(LinkConfigContext *ctx, Link *link);
 int link_apply_config(LinkConfigContext *ctx, Link *link);
 
-const char* mac_address_policy_to_string(MACAddressPolicy p) _const_;
-MACAddressPolicy mac_address_policy_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(mac_address_policy, MACAddressPolicy);
 
 /* gperf lookup function */
 const struct ConfigPerfItem* link_config_gperf_lookup(const char *str, GPERF_LEN_TYPE length);
index 19d6e7e0e1598b70906ae08f49672ec233cfe7ec..c23ad54c76b71d5620187a4f4fadc44cfdd32d7a 100644 (file)
@@ -17,5 +17,4 @@ bool udev_rules_should_reload(UdevRules *rules);
 int udev_rules_apply_to_event(UdevRules *rules, UdevEvent *event);
 int udev_rules_apply_static_dev_perms(UdevRules *rules);
 
-ResolveNameTiming resolve_name_timing_from_string(const char *s) _pure_;
-const char* resolve_name_timing_to_string(ResolveNameTiming i) _const_;
+DECLARE_STRING_TABLE_LOOKUP(resolve_name_timing, ResolveNameTiming);
index 072102eeecda331fae39e02bc5decb91204eb51b..d60f3e18781e0abfcde5915c8780e7416503e30b 100644 (file)
@@ -21,5 +21,4 @@ typedef enum SettingsMask {
         _SETTING_FORCE_ENUM_WIDTH = UINT64_MAX
 } SettingsMask;
 
-const char* console_mode_to_string(ConsoleMode m) _const_;
-ConsoleMode console_mode_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(console_mode, ConsoleMode);
index 97ddbb7fc8412d2f8ce6265d1b22b7a1dee2f411..0d138c84c8c74a92bca65a45819b7a53d3de1603 100644 (file)
@@ -82,8 +82,7 @@ static const char* const network_stack_table[_NETWORK_STACK_MAX] = {
         [NETWORK_STACK_NONE] = "none",
 };
 
-const char* network_stack_to_string(NetworkStack type) _const_;
-NetworkStack network_stack_from_string(const char *s) _pure_;
+DECLARE_STRING_TABLE_LOOKUP(network_stack, NetworkStack);
 
 int qemu_check_kvm_support(void);
 int qemu_check_vsock_support(void);