summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-05-02 22:51:50 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-05-02 22:52:09 -0400
commit44a6b1b68029833893f6e9cee35aa27a974038f6 (patch)
tree170b79abd66a206598ac095156a6c4012d0583f4
parent2f79c10e9aef916efbcf29315eea8c25d0a50ac4 (diff)
downloadsystemd-44a6b1b68029833893f6e9cee35aa27a974038f6.tar.gz
Add __attribute__((const, pure, format)) in various places
I'm assuming that it's fine if a _const_ or _pure_ function calls assert. It is assumed that the assert won't trigger, and even if it does, it can only trigger on the first call with a given set of parameters, and we don't care if the compiler moves the order of calls.
-rw-r--r--src/core/automount.h8
-rw-r--r--src/core/cgroup-attr.h4
-rw-r--r--src/core/cgroup.h2
-rw-r--r--src/core/condition.h4
-rw-r--r--src/core/device.c4
-rw-r--r--src/core/device.h4
-rw-r--r--src/core/execute.c4
-rw-r--r--src/core/execute.h8
-rw-r--r--src/core/job.c4
-rw-r--r--src/core/job.h26
-rw-r--r--src/core/kill.h10
-rw-r--r--src/core/manager.h2
-rw-r--r--src/core/mount.c10
-rw-r--r--src/core/mount.h12
-rw-r--r--src/core/path.c4
-rw-r--r--src/core/path.h12
-rw-r--r--src/core/selinux-access.c2
-rw-r--r--src/core/service.c8
-rw-r--r--src/core/service.h28
-rw-r--r--src/core/snapshot.c4
-rw-r--r--src/core/snapshot.h4
-rw-r--r--src/core/socket.c10
-rw-r--r--src/core/socket.h14
-rw-r--r--src/core/swap.c6
-rw-r--r--src/core/swap.h12
-rw-r--r--src/core/target.c4
-rw-r--r--src/core/target.h4
-rw-r--r--src/core/timer.c4
-rw-r--r--src/core/timer.h12
-rw-r--r--src/core/transaction.c4
-rw-r--r--src/core/unit.c4
-rw-r--r--src/core/unit.h26
-rw-r--r--src/journal/catalog.h2
-rw-r--r--src/journal/fsprg.c2
-rw-r--r--src/journal/fsprg.h10
-rw-r--r--src/journal/journal-file.c2
-rw-r--r--src/journal/journal-file.h6
-rw-r--r--src/journal/journal-send.c2
-rw-r--r--src/journal/journald-rate-limit.c2
-rw-r--r--src/journal/journald-server.h8
-rw-r--r--src/journal/journald-syslog.h2
-rw-r--r--src/journal/lookup3.h8
-rw-r--r--src/journal/mmap-cache.c2
-rw-r--r--src/journal/sd-journal.c2
-rw-r--r--src/login/logind-action.h4
-rw-r--r--src/login/logind-session.h16
-rw-r--r--src/login/logind-user.h4
-rw-r--r--src/shared/calendarspec.c4
-rw-r--r--src/shared/cgroup-util.c2
-rw-r--r--src/shared/cgroup-util.h2
-rw-r--r--src/shared/dbus-common.h8
-rw-r--r--src/shared/env-util.c2
-rw-r--r--src/shared/env-util.h4
-rw-r--r--src/shared/exit-status.h2
-rw-r--r--src/shared/hashmap.h24
-rw-r--r--src/shared/install.h8
-rw-r--r--src/shared/log.h10
-rw-r--r--src/shared/logs-show.h4
-rw-r--r--src/shared/pager.h4
-rw-r--r--src/shared/path-lookup.h4
-rw-r--r--src/shared/path-util.h30
-rw-r--r--src/shared/prioq.c2
-rw-r--r--src/shared/prioq.h6
-rw-r--r--src/shared/socket-util.h10
-rw-r--r--src/shared/strv.h8
-rw-r--r--src/shared/time-util.h4
-rw-r--r--src/shared/unit-name.h22
-rw-r--r--src/shared/util.c6
-rw-r--r--src/shared/util.h58
-rw-r--r--src/shared/utmp-wtmp.c2
-rw-r--r--src/shutdownd/shutdownd.c2
-rw-r--r--src/systemctl/systemctl.c2
72 files changed, 291 insertions, 275 deletions
diff --git a/src/core/automount.h b/src/core/automount.h
index 8276051352..0c6b8a72e9 100644
--- a/src/core/automount.h
+++ b/src/core/automount.h
@@ -64,8 +64,8 @@ int automount_send_ready(Automount *a, int status);
int automount_add_one_mount_link(Automount *a, Mount *m);
-const char* automount_state_to_string(AutomountState i);
-AutomountState automount_state_from_string(const char *s);
+const char* automount_state_to_string(AutomountState i) _const_;
+AutomountState automount_state_from_string(const char *s) _pure_;
-const char* automount_result_to_string(AutomountResult i);
-AutomountResult automount_result_from_string(const char *s);
+const char* automount_result_to_string(AutomountResult i) _const_;
+AutomountResult automount_result_from_string(const char *s) _pure_;
diff --git a/src/core/cgroup-attr.h b/src/core/cgroup-attr.h
index 0b542981e8..3a13b7c92d 100644
--- a/src/core/cgroup-attr.h
+++ b/src/core/cgroup-attr.h
@@ -42,8 +42,8 @@ struct CGroupAttribute {
int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b);
int cgroup_attribute_apply_list(CGroupAttribute *first, CGroupBonding *b);
-bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name);
-CGroupAttribute *cgroup_attribute_find_list(CGroupAttribute *first, const char *controller, const char *name);
+bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name) _pure_;
+CGroupAttribute *cgroup_attribute_find_list(CGroupAttribute *first, const char *controller, const char *name) _pure_;
void cgroup_attribute_free(CGroupAttribute *a);
void cgroup_attribute_free_list(CGroupAttribute *first);
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index 2ff39e5767..6555d89e37 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -76,7 +76,7 @@ void cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root);
int cgroup_bonding_is_empty(CGroupBonding *b);
int cgroup_bonding_is_empty_list(CGroupBonding *first);
-CGroupBonding *cgroup_bonding_find_list(CGroupBonding *first, const char *controller);
+CGroupBonding *cgroup_bonding_find_list(CGroupBonding *first, const char *controller) _pure_;
char *cgroup_bonding_to_string(CGroupBonding *b);
diff --git a/src/core/condition.h b/src/core/condition.h
index 1797385d26..50ed955af9 100644
--- a/src/core/condition.h
+++ b/src/core/condition.h
@@ -66,5 +66,5 @@ bool condition_test_list(Condition *c);
void condition_dump(Condition *c, FILE *f, const char *prefix);
void condition_dump_list(Condition *c, FILE *f, const char *prefix);
-const char* condition_type_to_string(ConditionType t);
-int condition_type_from_string(const char *s);
+const char* condition_type_to_string(ConditionType t) _const_;
+int condition_type_from_string(const char *s) _pure_;
diff --git a/src/core/device.c b/src/core/device.c
index 734d3f32e1..e83e797787 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -124,13 +124,13 @@ static void device_dump(Unit *u, FILE *f, const char *prefix) {
prefix, strna(d->sysfs));
}
-static UnitActiveState device_active_state(Unit *u) {
+_pure_ static UnitActiveState device_active_state(Unit *u) {
assert(u);
return state_translation_table[DEVICE(u)->state];
}
-static const char *device_sub_state_to_string(Unit *u) {
+_pure_ static const char *device_sub_state_to_string(Unit *u) {
assert(u);
return device_state_to_string(DEVICE(u)->state);
diff --git a/src/core/device.h b/src/core/device.h
index 3c4604f60e..41e8de9703 100644
--- a/src/core/device.h
+++ b/src/core/device.h
@@ -52,5 +52,5 @@ extern const UnitVTable device_vtable;
void device_fd_event(Manager *m, int events);
-const char* device_state_to_string(DeviceState i);
-DeviceState device_state_from_string(const char *s);
+const char* device_state_to_string(DeviceState i) _const_;
+DeviceState device_state_from_string(const char *s) _pure_;
diff --git a/src/core/execute.c b/src/core/execute.c
index 5767037acd..3959ef9623 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -144,7 +144,7 @@ static int flags_fds(const int fds[], unsigned n_fds, bool nonblock) {
return 0;
}
-static const char *tty_path(const ExecContext *context) {
+_pure_ static const char *tty_path(const ExecContext *context) {
assert(context);
if (context->tty_path)
@@ -509,7 +509,7 @@ fail:
return r;
}
-static int write_confirm_message(const char *format, ...) {
+_printf_attr_(1, 2) static int write_confirm_message(const char *format, ...) {
int fd;
va_list ap;
diff --git a/src/core/execute.h b/src/core/execute.h
index 3ce9221ab1..15574dc97e 100644
--- a/src/core/execute.h
+++ b/src/core/execute.h
@@ -210,8 +210,8 @@ void exec_status_start(ExecStatus *s, pid_t pid);
void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status);
void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
-const char* exec_output_to_string(ExecOutput i);
-ExecOutput exec_output_from_string(const char *s);
+const char* exec_output_to_string(ExecOutput i) _const_;
+ExecOutput exec_output_from_string(const char *s) _pure_;
-const char* exec_input_to_string(ExecInput i);
-ExecInput exec_input_from_string(const char *s);
+const char* exec_input_to_string(ExecInput i) _const_;
+ExecInput exec_input_from_string(const char *s) _pure_;
diff --git a/src/core/job.c b/src/core/job.c
index 9a425a6da1..d304a16d06 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -569,7 +569,7 @@ int job_run_and_invalidate(Job *j) {
return r;
}
-static const char *job_get_status_message_format(Unit *u, JobType t, JobResult result) {
+_pure_ static const char *job_get_status_message_format(Unit *u, JobType t, JobResult result) {
const UnitStatusMessageFormats *format_table;
assert(u);
@@ -588,7 +588,7 @@ static const char *job_get_status_message_format(Unit *u, JobType t, JobResult r
return NULL;
}
-static const char *job_get_status_message_format_try_harder(Unit *u, JobType t, JobResult result) {
+_pure_ static const char *job_get_status_message_format_try_harder(Unit *u, JobType t, JobResult result) {
const char *format;
assert(u);
diff --git a/src/core/job.h b/src/core/job.h
index 45d0487451..d90bc96b76 100644
--- a/src/core/job.h
+++ b/src/core/job.h
@@ -183,22 +183,22 @@ void job_dependency_free(JobDependency *l);
int job_merge(Job *j, Job *other);
-JobType job_type_lookup_merge(JobType a, JobType b);
+JobType job_type_lookup_merge(JobType a, JobType b) _pure_;
-static inline bool job_type_is_mergeable(JobType a, JobType b) {
+_pure_ static inline bool job_type_is_mergeable(JobType a, JobType b) {
return job_type_lookup_merge(a, b) >= 0;
}
-static inline bool job_type_is_conflicting(JobType a, JobType b) {
+_pure_ static inline bool job_type_is_conflicting(JobType a, JobType b) {
return !job_type_is_mergeable(a, b);
}
-static inline bool job_type_is_superset(JobType a, JobType b) {
+_pure_ static inline bool job_type_is_superset(JobType a, JobType b) {
/* Checks whether operation a is a "superset" of b in its actions */
return a == job_type_lookup_merge(a, b);
}
-bool job_type_is_redundant(JobType a, UnitActiveState b);
+bool job_type_is_redundant(JobType a, UnitActiveState b) _pure_;
/* Collapses a state-dependent job type into a simpler type by observing
* the state of the unit which it is going to be applied to. */
@@ -221,14 +221,14 @@ char *job_dbus_path(Job *j);
void job_shutdown_magic(Job *j);
-const char* job_type_to_string(JobType t);
-JobType job_type_from_string(const char *s);
+const char* job_type_to_string(JobType t) _const_;
+JobType job_type_from_string(const char *s) _pure_;
-const char* job_state_to_string(JobState t);
-JobState job_state_from_string(const char *s);
+const char* job_state_to_string(JobState t) _const_;
+JobState job_state_from_string(const char *s) _pure_;
-const char* job_mode_to_string(JobMode t);
-JobMode job_mode_from_string(const char *s);
+const char* job_mode_to_string(JobMode t) _const_;
+JobMode job_mode_from_string(const char *s) _pure_;
-const char* job_result_to_string(JobResult t);
-JobResult job_result_from_string(const char *s);
+const char* job_result_to_string(JobResult t) _const_;
+JobResult job_result_from_string(const char *s) _pure_;
diff --git a/src/core/kill.h b/src/core/kill.h
index 3c9b0ab8db..71a0513e84 100644
--- a/src/core/kill.h
+++ b/src/core/kill.h
@@ -26,6 +26,8 @@ typedef struct KillContext KillContext;
#include <stdbool.h>
#include <stdio.h>
+#include "macro.h"
+
typedef enum KillMode {
/* The kill mode is a property of a unit. */
KILL_CONTROL_GROUP = 0,
@@ -53,8 +55,8 @@ typedef enum KillWho {
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);
-KillMode kill_mode_from_string(const char *s);
+const char *kill_mode_to_string(KillMode k) _const_;
+KillMode kill_mode_from_string(const char *s) _pure_;
-const char *kill_who_to_string(KillWho k);
-KillWho kill_who_from_string(const char *s);
+const char *kill_who_to_string(KillWho k) _const_;
+KillWho kill_who_from_string(const char *s) _pure_;
diff --git a/src/core/manager.h b/src/core/manager.h
index b9bd2099f8..bf833540ae 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -284,7 +284,7 @@ int manager_distribute_fds(Manager *m, FDSet *fds);
int manager_reload(Manager *m);
-bool manager_is_reloading_or_reexecuting(Manager *m);
+bool manager_is_reloading_or_reexecuting(Manager *m) _pure_;
void manager_reset_failed(Manager *m);
diff --git a/src/core/mount.c b/src/core/mount.c
index 4f245555f2..10073b50be 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -136,7 +136,7 @@ static void mount_done(Unit *u) {
unit_unwatch_timer(u, &m->timer_watch);
}
-static MountParameters* get_mount_parameters_fragment(Mount *m) {
+_pure_ static MountParameters* get_mount_parameters_fragment(Mount *m) {
assert(m);
if (m->from_fragment)
@@ -145,7 +145,7 @@ static MountParameters* get_mount_parameters_fragment(Mount *m) {
return NULL;
}
-static MountParameters* get_mount_parameters(Mount *m) {
+_pure_ static MountParameters* get_mount_parameters(Mount *m) {
assert(m);
if (m->from_proc_self_mountinfo)
@@ -1260,19 +1260,19 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
return 0;
}
-static UnitActiveState mount_active_state(Unit *u) {
+_pure_ static UnitActiveState mount_active_state(Unit *u) {
assert(u);
return state_translation_table[MOUNT(u)->state];
}
-static const char *mount_sub_state_to_string(Unit *u) {
+_pure_ static const char *mount_sub_state_to_string(Unit *u) {
assert(u);
return mount_state_to_string(MOUNT(u)->state);
}
-static bool mount_check_gc(Unit *u) {
+_pure_ static bool mount_check_gc(Unit *u) {
Mount *m = MOUNT(u);
assert(m);
diff --git a/src/core/mount.h b/src/core/mount.h
index 30c6d9b249..bcc10ee0d4 100644
--- a/src/core/mount.h
+++ b/src/core/mount.h
@@ -111,13 +111,13 @@ extern const UnitVTable mount_vtable;
void mount_fd_event(Manager *m, int events);
-const char* mount_state_to_string(MountState i);
-MountState mount_state_from_string(const char *s);
+const char* mount_state_to_string(MountState i) _const_;
+MountState mount_state_from_string(const char *s) _pure_;
-const char* mount_exec_command_to_string(MountExecCommand i);
-MountExecCommand mount_exec_command_from_string(const char *s);
+const char* mount_exec_command_to_string(MountExecCommand i) _const_;
+MountExecCommand mount_exec_command_from_string(const char *s) _pure_;
-const char* mount_result_to_string(MountResult i);
-MountResult mount_result_from_string(const char *s);
+const char* mount_result_to_string(MountResult i) _const_;
+MountResult mount_result_from_string(const char *s) _pure_;
void warn_if_dir_nonempty(const char *unit, const char* where);
diff --git a/src/core/path.c b/src/core/path.c
index ab1fe2eb65..8a09deb4ff 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -680,13 +680,13 @@ static int path_deserialize_item(Unit *u, const char *key, const char *value, FD
return 0;
}
-static UnitActiveState path_active_state(Unit *u) {
+_pure_ static UnitActiveState path_active_state(Unit *u) {
assert(u);
return state_translation_table[PATH(u)->state];
}
-static const char *path_sub_state_to_string(Unit *u) {
+_pure_ static const char *path_sub_state_to_string(Unit *u) {
assert(u);
return path_state_to_string(PATH(u)->state);
diff --git a/src/core/path.h b/src/core/path.h
index 974041539b..6adab5897d 100644
--- a/src/core/path.h
+++ b/src/core/path.h
@@ -98,11 +98,11 @@ void path_free_specs(Path *p);
extern const UnitVTable path_vtable;
-const char* path_state_to_string(PathState i);
-PathState path_state_from_string(const char *s);
+const char* path_state_to_string(PathState i) _const_;
+PathState path_state_from_string(const char *s) _pure_;
-const char* path_type_to_string(PathType i);
-PathType path_type_from_string(const char *s);
+const char* path_type_to_string(PathType i) _const_;
+PathType path_type_from_string(const char *s) _pure_;
-const char* path_result_to_string(PathResult i);
-PathResult path_result_from_string(const char *s);
+const char* path_result_to_string(PathResult i) _const_;
+PathResult path_result_from_string(const char *s) _pure_;
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index bc195f3c56..426aed07d2 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -174,7 +174,7 @@ static int audit_callback(
user_avc's into the /var/log/audit/audit.log, otherwise they will be
sent to syslog.
*/
-static int log_callback(int type, const char *fmt, ...) {
+_printf_attr_(2, 3) static int log_callback(int type, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
diff --git a/src/core/service.c b/src/core/service.c
index 5803f798e0..3617c24711 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1878,7 +1878,7 @@ static int main_pid_good(Service *s) {
return -EAGAIN;
}
-static int control_pid_good(Service *s) {
+_pure_ static int control_pid_good(Service *s) {
assert(s);
return s->control_pid > 0;
@@ -2570,7 +2570,7 @@ static int service_reload(Unit *u) {
return 0;
}
-static bool service_can_reload(Unit *u) {
+_pure_ static bool service_can_reload(Unit *u) {
Service *s = SERVICE(u);
assert(s);
@@ -2782,7 +2782,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
return 0;
}
-static UnitActiveState service_active_state(Unit *u) {
+_pure_ static UnitActiveState service_active_state(Unit *u) {
const UnitActiveState *table;
assert(u);
@@ -2818,7 +2818,7 @@ static bool service_check_gc(Unit *u) {
return false;
}
-static bool service_check_snapshot(Unit *u) {
+_pure_ static bool service_check_snapshot(Unit *u) {
Service *s = SERVICE(u);
assert(s);
diff --git a/src/core/service.h b/src/core/service.h
index d1e53bf727..703d3faa45 100644
--- a/src/core/service.h
+++ b/src/core/service.h
@@ -203,23 +203,23 @@ struct Socket;
int service_set_socket_fd(Service *s, int fd, struct Socket *socket);
-const char* service_state_to_string(ServiceState i);
-ServiceState service_state_from_string(const char *s);
+const char* service_state_to_string(ServiceState i) _const_;
+ServiceState service_state_from_string(const char *s) _pure_;
-const char* service_restart_to_string(ServiceRestart i);
-ServiceRestart service_restart_from_string(const char *s);
+const char* service_restart_to_string(ServiceRestart i) _const_;
+ServiceRestart service_restart_from_string(const char *s) _pure_;
-const char* service_type_to_string(ServiceType i);
-ServiceType service_type_from_string(const char *s);
+const char* service_type_to_string(ServiceType i) _const_;
+ServiceType service_type_from_string(const char *s) _pure_;
-const char* service_exec_command_to_string(ServiceExecCommand i);
-ServiceExecCommand service_exec_command_from_string(const char *s);
+const char* service_exec_command_to_string(ServiceExecCommand i) _const_;
+ServiceExecCommand service_exec_command_from_string(const char *s) _pure_;
-const char* notify_access_to_string(NotifyAccess i);
-NotifyAccess notify_access_from_string(const char *s);
+const char* notify_access_to_string(NotifyAccess i) _const_;
+NotifyAccess notify_access_from_string(const char *s) _pure_;
-const char* service_result_to_string(ServiceResult i);
-ServiceResult service_result_from_string(const char *s);
+const char* service_result_to_string(ServiceResult i) _const_;
+ServiceResult service_result_from_string(const char *s) _pure_;
-const char* start_limit_action_to_string(StartLimitAction i);
-StartLimitAction start_limit_action_from_string(const char *s);
+const char* start_limit_action_to_string(StartLimitAction i) _const_;
+StartLimitAction start_limit_action_from_string(const char *s) _pure_;
diff --git a/src/core/snapshot.c b/src/core/snapshot.c
index a3f5e908eb..a63eccd8de 100644
--- a/src/core/snapshot.c
+++ b/src/core/snapshot.c
@@ -173,13 +173,13 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value
return 0;
}
-static UnitActiveState snapshot_active_state(Unit *u) {
+_pure_ static UnitActiveState snapshot_active_state(Unit *u) {
assert(u);
return state_translation_table[SNAPSHOT(u)->state];
}
-static const char *snapshot_sub_state_to_string(Unit *u) {
+_pure_ static const char *snapshot_sub_state_to_string(Unit *u) {
assert(u);
return snapshot_state_to_string(SNAPSHOT(u)->state);
diff --git a/src/core/snapshot.h b/src/core/snapshot.h
index 9662d93164..56f87cff4d 100644
--- a/src/core/snapshot.h
+++ b/src/core/snapshot.h
@@ -46,5 +46,5 @@ extern const UnitVTable snapshot_vtable;
int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **s);
void snapshot_remove(Snapshot *s);
-const char* snapshot_state_to_string(SnapshotState i);
-SnapshotState snapshot_state_from_string(const char *s);
+const char* snapshot_state_to_string(SnapshotState i) _const_;
+SnapshotState snapshot_state_from_string(const char *s) _pure_;
diff --git a/src/core/socket.c b/src/core/socket.c
index c276afe38f..8c829d3043 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -344,7 +344,7 @@ static int socket_add_default_dependencies(Socket *s) {
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
-static bool socket_has_exec(Socket *s) {
+_pure_ static bool socket_has_exec(Socket *s) {
unsigned i;
assert(s);
@@ -410,7 +410,7 @@ static int socket_load(Unit *u) {
return socket_verify(s);
}
-static const char* listen_lookup(int family, int type) {
+_const_ static const char* listen_lookup(int family, int type) {
if (family == AF_NETLINK)
return "ListenNetlink";
@@ -1957,13 +1957,13 @@ static int socket_distribute_fds(Unit *u, FDSet *fds) {
return 0;
}
-static UnitActiveState socket_active_state(Unit *u) {
+_pure_ static UnitActiveState socket_active_state(Unit *u) {
assert(u);
return state_translation_table[SOCKET(u)->state];
}
-static const char *socket_sub_state_to_string(Unit *u) {
+_pure_ static const char *socket_sub_state_to_string(Unit *u) {
assert(u);
return socket_state_to_string(SOCKET(u)->state);
@@ -1991,7 +1991,7 @@ const char* socket_port_type_to_string(SocketPort *p) {
}
}
-static bool socket_check_gc(Unit *u) {
+_pure_ static bool socket_check_gc(Unit *u) {
Socket *s = SOCKET(u);
assert(u);
diff --git a/src/core/socket.h b/src/core/socket.h
index dbc363217b..4826bb331b 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -167,13 +167,13 @@ void socket_free_ports(Socket *s);
extern const UnitVTable socket_vtable;
-const char* socket_state_to_string(SocketState i);
-SocketState socket_state_from_string(const char *s);
+const char* socket_state_to_string(SocketState i) _const_;
+SocketState socket_state_from_string(const char *s) _pure_;
-const char* socket_exec_command_to_string(SocketExecCommand i);
-SocketExecCommand socket_exec_command_from_string(const char *s);
+const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
+SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
-const char* socket_result_to_string(SocketResult i);
-SocketResult socket_result_from_string(const char *s);
+const char* socket_result_to_string(SocketResult i) _const_;
+SocketResult socket_result_from_string(const char *s) _pure_;
-const char* socket_port_type_to_string(SocketPort *p);
+const char* socket_port_type_to_string(SocketPort *p) _pure_;
diff --git a/src/core/swap.c b/src/core/swap.c
index e7cc19596e..d503fe20df 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -899,19 +899,19 @@ static int swap_deserialize_item(Unit *u, const char *key, const char *value, FD
return 0;
}
-static UnitActiveState swap_active_state(Unit *u) {
+_pure_ static UnitActiveState swap_active_state(Unit *u) {
assert(u);
return state_translation_table[SWAP(u)->state];
}
-static const char *swap_sub_state_to_string(Unit *u) {
+_pure_ static const char *swap_sub_state_to_string(Unit *u) {
assert(u);
return swap_state_to_string(SWAP(u)->state);
}
-static bool swap_check_gc(Unit *u) {
+_pure_ static bool swap_check_gc(Unit *u) {
Swap *s = SWAP(u);
assert(s);
diff --git a/src/core/swap.h b/src/core/swap.h
index 35d47fd46f..121889d1d5 100644
--- a/src/core/swap.h
+++ b/src/core/swap.h
@@ -111,11 +111,11 @@ int swap_add_one_mount_link(Swap *s, Mount *m);
int swap_dispatch_reload(Manager *m);
int swap_fd_event(Manager *m, int events);
-const char* swap_state_to_string(SwapState i);
-SwapState swap_state_from_string(const char *s);
+const char* swap_state_to_string(SwapState i) _const_;
+SwapState swap_state_from_string(const char *s) _pure_;
-const char* swap_exec_command_to_string(SwapExecCommand i);
-SwapExecCommand swap_exec_command_from_string(const char *s);
+const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
+SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
-const char* swap_result_to_string(SwapResult i);
-SwapResult swap_result_from_string(const char *s);
+const char* swap_result_to_string(SwapResult i) _const_;
+SwapResult swap_result_from_string(const char *s) _pure_;
diff --git a/src/core/target.c b/src/core/target.c
index 981424132b..3fffa0d2f5 100644
--- a/src/core/target.c
+++ b/src/core/target.c
@@ -184,13 +184,13 @@ static int target_deserialize_item(Unit *u, const char *key, const char *value,
return 0;
}
-static UnitActiveState target_active_state(Unit *u) {
+_pure_ static UnitActiveState target_active_state(Unit *u) {
assert(u);
return state_translation_table[TARGET(u)->state];
}
-static const char *target_sub_state_to_string(Unit *u) {
+_pure_ static const char *target_sub_state_to_string(Unit *u) {
assert(u);
return target_state_to_string(TARGET(u)->state);
diff --git a/src/core/target.h b/src/core/target.h
index 1676553add..a5398d9e98 100644
--- a/src/core/target.h
+++ b/src/core/target.h
@@ -40,5 +40,5 @@ struct Target {
extern const UnitVTable target_vtable;
-const char* target_state_to_string(TargetState i);
-TargetState target_state_from_string(const char *s);
+const char* target_state_to_string(TargetState i) _const_;
+TargetState target_state_from_string(const char *s) _pure_;
diff --git a/src/core/timer.c b/src/core/timer.c
index ff8c30583c..9166c1e2fc 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -464,13 +464,13 @@ static int timer_deserialize_item(Unit *u, const char *key, const char *value, F
return 0;
}
-static UnitActiveState timer_active_state(Unit *u) {
+_pure_ static UnitActiveState timer_active_state(Unit *u) {
assert(u);
return state_translation_table[TIMER(u)->state];
}
-static const char *timer_sub_state_to_string(Unit *u) {
+_pure_ static const char *timer_sub_state_to_string(Unit *u) {
assert(u);
return timer_state_to_string(TIMER(u)->state);
diff --git a/src/core/timer.h b/src/core/timer.h
index fed15e9165..4168553e9d 100644
--- a/src/core/timer.h
+++ b/src/core/timer.h
@@ -87,11 +87,11 @@ void timer_free_values(Timer *t);
extern const UnitVTable timer_vtable;
-const char *timer_state_to_string(TimerState i);
-TimerState timer_state_from_string(const char *s);
+const char *timer_state_to_string(TimerState i) _const_;
+TimerState timer_state_from_string(const char *s) _pure_;
-const char *timer_base_to_string(TimerBase i);
-TimerBase timer_base_from_string(const char *s);
+const char *timer_base_to_string(TimerBase i) _const_;
+TimerBase timer_base_from_string(const char *s) _pure_;
-const char* timer_result_to_string(TimerResult i);
-TimerResult timer_result_from_string(const char *s);
+const char* timer_result_to_string(TimerResult i) _const_;
+TimerResult timer_result_from_string(const char *s) _pure_;
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 610344eff3..fa97b69755 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -140,7 +140,7 @@ static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other
transaction_delete_job(tr, other, true);
}
-static bool job_is_conflicted_by(Job *j) {
+_pure_ static bool job_is_conflicted_by(Job *j) {
JobDependency *l;
assert(j);
@@ -320,7 +320,7 @@ rescan:
}
}
-static bool unit_matters_to_anchor(Unit *u, Job *j) {
+_pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) {
assert(u);
assert(!j->transaction_prev);
diff --git a/src/core/unit.c b/src/core/unit.c
index c0f156c928..dc8bf83383 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -949,7 +949,7 @@ bool unit_condition_test(Unit *u) {
return u->condition_result;
}
-static const char* unit_get_status_message_format(Unit *u, JobType t) {
+_pure_ static const char* unit_get_status_message_format(Unit *u, JobType t) {
const UnitStatusMessageFormats *format_table;
assert(u);
@@ -966,7 +966,7 @@ static const char* unit_get_status_message_format(Unit *u, JobType t) {
return format_table->starting_stopping[t == JOB_STOP];
}
-static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
+_pure_ static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
const char *format;
assert(u);
diff --git a/src/core/unit.h b/src/core/unit.h
index 0f121e244e..b04475e4fb 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -468,13 +468,13 @@ void unit_add_to_gc_queue(Unit *u);
int unit_merge(Unit *u, Unit *other);
int unit_merge_by_name(Unit *u, const char *other);
-Unit *unit_follow_merge(Unit *u);
+Unit *unit_follow_merge(Unit *u) _pure_;
int unit_load_fragment_and_dropin(Unit *u);
int unit_load_fragment_and_dropin_optional(Unit *u);
int unit_load(Unit *unit);
-const char *unit_description(Unit *u);
+const char *unit_description(Unit *u) _pure_;
bool unit_has_name(Unit *u, const char *name);
@@ -484,9 +484,9 @@ const char* unit_sub_state_to_string(Unit *u);
void unit_dump(Unit *u, FILE *f, const char *prefix);
-bool unit_can_reload(Unit *u);
-bool unit_can_start(Unit *u);
-bool unit_can_isolate(Unit *u);
+bool unit_can_reload(Unit *u) _pure_;
+bool unit_can_start(Unit *u) _pure_;
+bool unit_can_isolate(Unit *u) _pure_;
int unit_start(Unit *u);
int unit_stop(Unit *u);
@@ -518,7 +518,7 @@ char *unit_dbus_path(Unit *u);
int unit_load_related_unit(Unit *u, const char *type, Unit **_found);
int unit_get_related_unit(Unit *u, const char *type, Unit **_found);
-bool unit_can_serialize(Unit *u);
+bool unit_can_serialize(Unit *u) _pure_;
int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs);
void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *value, ...) _printf_attr_(4,5);
void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value);
@@ -536,8 +536,8 @@ void unit_reset_failed(Unit *u);
Unit *unit_following(Unit *u);
-bool unit_stop_pending(Unit *u);
-bool unit_inactive_or_pending(Unit *u);
+bool unit_stop_pending(Unit *u) _pure_;
+bool unit_inactive_or_pending(Unit *u) _pure_;
bool unit_active_or_pending(Unit *u);
int unit_add_default_target_dependency(Unit *u, Unit *target);
@@ -563,18 +563,18 @@ int unit_add_mount_links(Unit *u);
int unit_exec_context_defaults(Unit *u, ExecContext *c);
-ExecContext *unit_get_exec_context(Unit *u);
+ExecContext *unit_get_exec_context(Unit *u) _pure_;
int unit_write_drop_in(Unit *u, bool runtime, const char *name, const char *data);
int unit_remove_drop_in(Unit *u, bool runtime, const char *name);
int unit_kill_context(Unit *u, KillContext *c, bool sigkill, pid_t main_pid, pid_t control_pid, bool main_pid_alien);
-const char *unit_active_state_to_string(UnitActiveState i);
-UnitActiveState unit_active_state_from_string(const char *s);
+const char *unit_active_state_to_string(UnitActiveState i) _const_;
+UnitActiveState unit_active_state_from_string(const char *s) _pure_;
-const char *unit_dependency_to_string(UnitDependency i);
-UnitDependency unit_dependency_from_string(const char *s);
+const char *unit_dependency_to_string(UnitDependency i) _const_;
+UnitDependency unit_dependency_from_string(const char *s) _pure_;
/* Macros which append UNIT= or USER_UNIT= to the message */
diff --git a/src/journal/catalog.h b/src/journal/catalog.h
index 89f8f93d03..24a2d0b553 100644
--- a/src/journal/catalog.h
+++ b/src/journal/catalog.h
@@ -29,7 +29,7 @@
int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path);
unsigned catalog_hash_func(const void *p);
-int catalog_compare_func(const void *a, const void *b);
+int catalog_compare_func(const void *a, const void *b) _pure_;
int catalog_update(const char* database, const char* root, const char* const* dirs);
int catalog_get(const char* database, sd_id128_t id, char **data);
int catalog_list(FILE *f, const char* database, bool oneline);
diff --git a/src/journal/fsprg.c b/src/journal/fsprg.c
index 2190b7c796..6817a629c8 100644
--- a/src/journal/fsprg.c
+++ b/src/journal/fsprg.c
@@ -74,7 +74,7 @@ static void uint64_export(void *buf, size_t buflen, uint64_t x) {
((uint8_t*) buf)[7] = (x >> 0) & 0xff;
}
-static uint64_t uint64_import(const void *buf, size_t buflen) {
+_pure_ static uint64_t uint64_import(const void *buf, size_t buflen) {
assert(buflen == 8);
return
(uint64_t)(((uint8_t*) buf)[0]) << 56 |
diff --git a/src/journal/fsprg.h b/src/journal/fsprg.h
index 306ef18d73..150d034828 100644
--- a/src/journal/fsprg.h
+++ b/src/journal/fsprg.h
@@ -28,6 +28,8 @@
#include <sys/types.h>
#include <inttypes.h>
+#include "macro.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -35,9 +37,9 @@ extern "C" {
#define FSPRG_RECOMMENDED_SECPAR 1536
#define FSPRG_RECOMMENDED_SEEDLEN (96/8)
-size_t FSPRG_mskinbytes(unsigned secpar);
-size_t FSPRG_mpkinbytes(unsigned secpar);
-size_t FSPRG_stateinbytes(unsigned secpar);
+size_t FSPRG_mskinbytes(unsigned secpar) _const_;
+size_t FSPRG_mpkinbytes(unsigned secpar) _const_;
+size_t FSPRG_stateinbytes(unsigned secpar) _const_;
/* Setup msk and mpk. Providing seed != NULL makes this algorithm deterministic. */
void FSPRG_GenMK(void *msk, void *mpk, const void *seed, size_t seedlen, unsigned secpar);
@@ -50,7 +52,7 @@ void FSPRG_GenState0(void *state, const void *mpk, const void *seed, size_t seed
void FSPRG_Evolve(void *state);
-uint64_t FSPRG_GetEpoch(const void *state);
+uint64_t FSPRG_GetEpoch(const void *state) _pure_;
/* Seek to any arbitrary state (by providing msk together with seed from GenState0). */
void FSPRG_Seek(void *state, uint64_t epoch, const void *msk, const void *seed, size_t seedlen);
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index a44e126c0e..876224dc9f 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1712,7 +1712,7 @@ found:
return 1;
}
-static int test_object_offset(JournalFile *f, uint64_t p, uint64_t needle) {
+_pure_ static int test_object_offset(JournalFile *f, uint64_t p, uint64_t needle) {
assert(f);
assert(p > 0);
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index 0eab5017d7..7b1cd42854 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -150,9 +150,9 @@ static inline bool VALID_EPOCH(uint64_t u) {
int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Object **ret);
-uint64_t journal_file_entry_n_items(Object *o);
-uint64_t journal_file_entry_array_n_items(Object *o);
-uint64_t journal_file_hash_table_n_items(Object *o);
+uint64_t journal_file_entry_n_items(Object *o) _pure_;
+uint64_t journal_file_entry_array_n_items(Object *o) _pure_;
+uint64_t journal_file_hash_table_n_items(Object *o) _pure_;
int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object **ret, uint64_t *offset);
int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset);
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 4b9109a3c8..14c437da78 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -111,7 +111,7 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) {
return sd_journal_sendv(iov, 2);
}
-static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct iovec **_iov) {
+_printf_attr_(1, 0) static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct iovec **_iov) {
PROTECT_ERRNO;
int r, n = 0, i = 0, j;
struct iovec *iov = NULL;
diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c
index da3aed64ea..32e35a926d 100644
--- a/src/journal/journald-rate-limit.c
+++ b/src/journal/journald-rate-limit.c
@@ -115,7 +115,7 @@ void journal_rate_limit_free(JournalRateLimit *r) {
free(r);
}
-static bool journal_rate_limit_group_expired(JournalRateLimitGroup *g, usec_t ts) {
+_pure_ static bool journal_rate_limit_group_expired(JournalRateLimitGroup *g, usec_t ts) {
unsigned i;
assert(g);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 86f7145292..129f7e8ab4 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -137,13 +137,13 @@ const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned len
int config_parse_storage(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-const char *storage_to_string(Storage s);
-Storage storage_from_string(const char *s);
+const char *storage_to_string(Storage s) _const_;
+Storage storage_from_string(const char *s) _pure_;
int config_parse_split_mode(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-const char *split_mode_to_string(SplitMode s);
-SplitMode split_mode_from_string(const char *s);
+const char *split_mode_to_string(SplitMode s) _const_;
+SplitMode split_mode_from_string(const char *s) _pure_;
void server_fix_perms(Server *s, JournalFile *f, uid_t uid);
bool shall_try_append_again(JournalFile *f, int r);
diff --git a/src/journal/journald-syslog.h b/src/journal/journald-syslog.h
index 7ff215b524..324b70eef0 100644
--- a/src/journal/journald-syslog.h
+++ b/src/journal/journald-syslog.h
@@ -23,7 +23,7 @@
#include "journald-server.h"
-int syslog_fixup_facility(int priority);
+int syslog_fixup_facility(int priority) _const_;
void syslog_parse_priority(char **p, int *priority);
size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid);
diff --git a/src/journal/lookup3.h b/src/journal/lookup3.h
index 502b42c209..3224473a6a 100644
--- a/src/journal/lookup3.h
+++ b/src/journal/lookup3.h
@@ -5,13 +5,15 @@
#include <inttypes.h>
#include <sys/types.h>
-uint32_t jenkins_hashword(const uint32_t *k, size_t length, uint32_t initval);
+#include "macro.h"
+
+uint32_t jenkins_hashword(const uint32_t *k, size_t length, uint32_t initval) _pure_;
void jenkins_hashword2(const uint32_t *k, size_t length, uint32_t *pc, uint32_t *pb);
-uint32_t jenkins_hashlittle(const void *key, size_t length, uint32_t initval);
+uint32_t jenkins_hashlittle(const void *key, size_t length, uint32_t initval) _pure_;
void jenkins_hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
-uint32_t jenkins_hashbig(const void *key, size_t length, uint32_t initval);
+uint32_t jenkins_hashbig(const void *key, size_t length, uint32_t initval) _pure_;
static inline uint64_t hash64(const void *data, size_t length) {
uint32_t a = 0, b = 0;
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 251aefe121..54bf1148e1 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -134,7 +134,7 @@ static void window_free(Window *w) {
free(w);
}
-static bool window_matches(Window *w, int fd, int prot, uint64_t offset, size_t size) {
+_pure_ static bool window_matches(Window *w, int fd, int prot, uint64_t offset, size_t size) {
assert(w);
assert(fd >= 0);
assert(size > 0);
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 15239b5688..d81e4ddfa9 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -498,7 +498,7 @@ static int compare_entry_order(JournalFile *af, Object *_ao,
return 0;
}
-static int compare_with_location(JournalFile *af, Object *ao, Location *l) {
+_pure_ static int compare_with_location(JournalFile *af, Object *ao, Location *l) {
uint64_t a;
assert(af);
diff --git a/src/login/logind-action.h b/src/login/logind-action.h
index df080d98ed..552713637d 100644
--- a/src/login/logind-action.h
+++ b/src/login/logind-action.h
@@ -46,8 +46,8 @@ int manager_handle_action(
bool ignore_inhibited,
bool is_edge);
-const char* handle_action_to_string(HandleAction h);
-HandleAction handle_action_from_string(const char *s);
+const char* handle_action_to_string(HandleAction h) _const_;
+HandleAction handle_action_from_string(const char *s) _pure_;
int config_parse_handle_action(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index c8dd181e7b..a73df3a3bc 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -135,14 +135,14 @@ int session_send_changed(Session *s, const char *properties);
int session_send_lock(Session *s, bool lock);
int session_send_lock_all(Manager *m, bool lock);
-const char* session_state_to_string(SessionState t);
-SessionState session_state_from_string(const char *s);
+const char* session_state_to_string(SessionState t) _const_;
+SessionState session_state_from_string(const char *s) _pure_;
-const char* session_type_to_string(SessionType t);
-SessionType session_type_from_string(const char *s);
+const char* session_type_to_string(SessionType t) _const_;
+SessionType session_type_from_string(const char *s) _pure_;
-const char* session_class_to_string(SessionClass t);
-SessionClass session_class_from_string(const char *s);
+const char* session_class_to_string(SessionClass t) _const_;
+SessionClass session_class_from_string(const char *s) _pure_;
-const char *kill_who_to_string(KillWho k);
-KillWho kill_who_from_string(const char *s);
+const char *kill_who_to_string(KillWho k) _const_;
+KillWho kill_who_from_string(const char *s) _pure_;
diff --git a/src/login/logind-user.h b/src/login/logind-user.h
index a679d43a30..080354da74 100644
--- a/src/login/logind-user.h
+++ b/src/login/logind-user.h
@@ -80,5 +80,5 @@ extern const DBusObjectPathVTable bus_user_vtable;
int user_send_signal(User *u, bool new_user);
int user_send_changed(User *u, const char *properties);
-const char* user_state_to_string(UserState s);
-UserState user_state_from_string(const char *s);
+const char* user_state_to_string(UserState s) _const_;
+UserState user_state_from_string(const char *s) _pure_;
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index 13f70d8e72..7979e2384f 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -133,7 +133,7 @@ int calendar_spec_normalize(CalendarSpec *c) {
return 0;
}
-static bool chain_valid(CalendarComponent *c, int from, int to) {
+_pure_ static bool chain_valid(CalendarComponent *c, int from, int to) {
if (!c)
return true;
@@ -149,7 +149,7 @@ static bool chain_valid(CalendarComponent *c, int from, int to) {
return true;
}
-bool calendar_spec_valid(CalendarSpec *c) {
+_pure_ bool calendar_spec_valid(CalendarSpec *c) {
assert(c);
if (c->weekdays_bits > 127)
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 8c2ef45530..c5a5f8df83 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1311,7 +1311,7 @@ int cg_pid_get_unit(pid_t pid, char **unit) {
return cg_path_get_unit(cgroup, unit);
}
-static const char *skip_label(const char *e) {
+_pure_ static const char *skip_label(const char *e) {
assert(e);
e = strchr(e, '/');
diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h
index 92caa0c448..25dd277ba5 100644
--- a/src/shared/cgroup-util.h
+++ b/src/shared/cgroup-util.h
@@ -110,6 +110,6 @@ char **cg_shorten_controllers(char **controllers);
int cg_controller_from_attr(const char *attr, char **controller);
char *cg_escape(const char *p);
-char *cg_unescape(const char *p);
+char *cg_unescape(const char *p) _pure_;
bool cg_controller_is_valid(const char *p, bool allow_named);
diff --git a/src/shared/dbus-common.h b/src/shared/dbus-common.h
index 16fc14b8e4..9752f08c05 100644
--- a/src/shared/dbus-common.h
+++ b/src/shared/dbus-common.h
@@ -25,6 +25,8 @@
#include <inttypes.h>
#include <sys/types.h>
+#include "macro.h"
+
#ifndef DBUS_ERROR_UNKNOWN_OBJECT
#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
#endif
@@ -187,13 +189,13 @@ int bus_property_set_uint64(DBusMessageIter *i, const char *property, void *data
return 0; \
}
-const char *bus_errno_to_dbus(int error);
+const char *bus_errno_to_dbus(int error) _const_;
DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
DBusMessage* bus_properties_changed_one_new(const char *path, const char *interface, const char *property);
-uint32_t bus_flags_to_events(DBusWatch *bus_watch);
-unsigned bus_events_to_flags(uint32_t events);
+uint32_t bus_flags_to_events(DBusWatch *bus_watch) _pure_;
+unsigned bus_events_to_flags(uint32_t events) _const_;
int bus_parse_strv(DBusMessage *m, char ***_l);
int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l);
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
index d3d4c59ab9..6a52fb960d 100644
--- a/src/shared/env-util.c
+++ b/src/shared/env-util.c
@@ -227,7 +227,7 @@ fail:
return NULL;
}
-static bool env_match(const char *t, const char *pattern) {
+_pure_ static bool env_match(const char *t, const char *pattern) {
assert(t);
assert(pattern);
diff --git a/src/shared/env-util.h b/src/shared/env-util.h
index b2e520c102..8d2114b64c 100644
--- a/src/shared/env-util.h
+++ b/src/shared/env-util.h
@@ -40,5 +40,5 @@ char **strv_env_delete(char **x, unsigned n_lists, ...); /* New copy */
char **strv_env_set(char **x, const char *p); /* New copy ... */
char **strv_env_unset(char **l, const char *p); /* In place ... */
-char *strv_env_get_n(char **l, const char *name, size_t k);
-char *strv_env_get(char **x, const char *n);
+char *strv_env_get_n(char **l, const char *name, size_t k) _pure_;
+char *strv_env_get(char **x, const char *n) _pure_;
diff --git a/src/shared/exit-status.h b/src/shared/exit-status.h
index d3b548fc96..1f035a3007 100644
--- a/src/shared/exit-status.h
+++ b/src/shared/exit-status.h
@@ -82,7 +82,7 @@ typedef struct ExitStatusSet {
Set *signal;
} ExitStatusSet;
-const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level);
+const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) _const_;
bool is_clean_exit(int code, int status, ExitStatusSet *success_status);
bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status);
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index f52517f476..8f6e644b25 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -23,6 +23,8 @@
#include <stdbool.h>
+#include "macro.h"
+
/* Pretty straightforward hash table implementation. As a minor
* optimization a NULL hashmap object will be treated as empty hashmap
* for all read operations. That way it is not necessary to
@@ -38,14 +40,14 @@ typedef _IteratorStruct* Iterator;
typedef unsigned (*hash_func_t)(const void *p);
typedef int (*compare_func_t)(const void *a, const void *b);
-unsigned string_hash_func(const void *p);
-int string_compare_func(const void *a, const void *b);
+unsigned string_hash_func(const void *p) _pure_;
+int string_compare_func(const void *a, const void *b) _pure_;
-unsigned trivial_hash_func(const void *p);
-int trivial_compare_func(const void *a, const void *b);
+unsigned trivial_hash_func(const void *p) _const_;
+int trivial_compare_func(const void *a, const void *b) _const_;
-unsigned uint64_hash_func(const void *p);
-int uint64_compare_func(const void *a, const void *b);
+unsigned uint64_hash_func(const void *p) _pure_;
+int uint64_compare_func(const void *a, const void *b) _pure_;
Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
void hashmap_free(Hashmap *h);
@@ -69,8 +71,8 @@ int hashmap_merge(Hashmap *h, Hashmap *other);
void hashmap_move(Hashmap *h, Hashmap *other);
int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key);
-unsigned hashmap_size(Hashmap *h);
-bool hashmap_isempty(Hashmap *h);
+unsigned hashmap_size(Hashmap *h) _pure_;
+bool hashmap_isempty(Hashmap *h) _pure_;
void *hashmap_iterate(Hashmap *h, Iterator *i, const void **key);
void *hashmap_iterate_backwards(Hashmap *h, Iterator *i, const void **key);
@@ -82,9 +84,9 @@ void hashmap_clear_free_free(Hashmap *h);
void *hashmap_steal_first(Hashmap *h);
void *hashmap_steal_first_key(Hashmap *h);
-void *hashmap_first(Hashmap *h);
-void *hashmap_first_key(Hashmap *h);
-void *hashmap_last(Hashmap *h);
+void *hashmap_first(Hashmap *h) _pure_;
+void *hashmap_first_key(Hashmap *h) _pure_;
+void *hashmap_last(Hashmap *h) _pure_;
void *hashmap_next(Hashmap *h, const void *key);
diff --git a/src/shared/install.h b/src/shared/install.h
index 755dddeb12..94516c9d05 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -90,8 +90,8 @@ void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes);
int unit_file_query_preset(UnitFileScope scope, const char *name);
-const char *unit_file_state_to_string(UnitFileState s);
-UnitFileState unit_file_state_from_string(const char *s);
+const char *unit_file_state_to_string(UnitFileState s) _const_;
+UnitFileState unit_file_state_from_string(const char *s) _pure_;
-const char *unit_file_change_type_to_string(UnitFileChangeType s);
-UnitFileChangeType unit_file_change_type_from_string(const char *s);
+const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
+UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
diff --git a/src/shared/log.h b/src/shared/log.h
index 5fc89880ad..979f833d57 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -56,8 +56,8 @@ void log_show_location(bool b);
int log_show_color_from_string(const char *e);
int log_show_location_from_string(const char *e);
-LogTarget log_get_target(void);
-int log_get_max_level(void);
+LogTarget log_get_target(void) _pure_;
+int log_get_max_level(void) _pure_;
int log_open(void);
void log_close(void);
@@ -151,9 +151,9 @@ _noreturn_ void log_assert_failed_unreachable(
/* This modifies the buffer passed! */
#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
-bool log_on_console(void);
+bool log_on_console(void) _pure_;
-const char *log_target_to_string(LogTarget target);
-LogTarget log_target_from_string(const char *s);
+const char *log_target_to_string(LogTarget target) _const_;
+LogTarget log_target_from_string(const char *s) _pure_;
#define MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x)
diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h
index 5a4c9f24d7..b0f93a661a 100644
--- a/src/shared/logs-show.h
+++ b/src/shared/logs-show.h
@@ -63,5 +63,5 @@ void json_escape(
size_t l,
OutputFlags flags);
-const char* output_mode_to_string(OutputMode m);
-OutputMode output_mode_from_string(const char *s);
+const char* output_mode_to_string(OutputMode m) _const_;
+OutputMode output_mode_from_string(const char *s) _pure_;
diff --git a/src/shared/pager.h b/src/shared/pager.h
index 325ca98f79..03dca8bc03 100644
--- a/src/shared/pager.h
+++ b/src/shared/pager.h
@@ -23,6 +23,8 @@
#include <stdbool.h>
+#include "macro.h"
+
int pager_open(bool jump_to_end);
void pager_close(void);
-bool pager_have(void);
+bool pager_have(void) _pure_;
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index baef62228a..9dee85f967 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -36,8 +36,8 @@ typedef enum SystemdRunningAs {
_SYSTEMD_RUNNING_AS_INVALID = -1
} SystemdRunningAs;
-const char* systemd_running_as_to_string(SystemdRunningAs i);
-SystemdRunningAs systemd_running_as_from_string(const char *s);
+const char* systemd_running_as_to_string(SystemdRunningAs i) _const_;
+SystemdRunningAs systemd_running_as_from_string(const char *s) _pure_;
int user_config_home(char **config_home);
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
index ea0f173082..d187743769 100644
--- a/src/shared/path-util.h
+++ b/src/shared/path-util.h
@@ -21,22 +21,24 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include "stdbool.h"
+#include <stdbool.h>
-bool is_path(const char *p);
-char **path_split_and_make_absolute(const char *p);
-char *path_get_file_name(const char *p);
+#include "macro.h"
+
+bool is_path(const char *p) _pure_;
+char** path_split_and_make_absolute(const char *p);
+char* path_get_file_name(const char *p) _pure_;
int path_get_parent(const char *path, char **parent);
-bool path_is_absolute(const char *p);
-char *path_make_absolute(const char *p, const char *prefix);
-char *path_make_absolute_cwd(const char *p);
-char *path_kill_slashes(char *path);
-char *path_startswith(const char *path, const char *prefix);
-bool path_equal(const char *a, const char *b);
-
-char **path_strv_make_absolute_cwd(char **l);
-char **path_strv_canonicalize(char **l);
-char **path_strv_canonicalize_uniq(char **l);
+bool path_is_absolute(const char *p) _pure_;
+char* path_make_absolute(const char *p, const char *prefix);
+char* path_make_absolute_cwd(const char *p);
+char* path_kill_slashes(char *path);
+char* path_startswith(const char *path, const char *prefix) _pure_;
+bool path_equal(const char *a, const char *b) _pure_;
+
+char** path_strv_make_absolute_cwd(char **l);
+char** path_strv_canonicalize(char **l);
+char** path_strv_canonicalize_uniq(char **l);
int path_is_mount_point(const char *path, bool allow_symlink);
int path_is_read_only_fs(const char *path);
diff --git a/src/shared/prioq.c b/src/shared/prioq.c
index a2205719b4..2d166360aa 100644
--- a/src/shared/prioq.c
+++ b/src/shared/prioq.c
@@ -211,7 +211,7 @@ static void remove_item(Prioq *q, struct prioq_item *i) {
}
}
-static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) {
+_pure_ static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) {
struct prioq_item *i;
assert(q);
diff --git a/src/shared/prioq.h b/src/shared/prioq.h
index 17679b2aaf..4a206a3e59 100644
--- a/src/shared/prioq.h
+++ b/src/shared/prioq.h
@@ -33,8 +33,8 @@ int prioq_put(Prioq *q, void *data, unsigned *idx);
int prioq_remove(Prioq *q, void *data, unsigned *idx);
int prioq_reshuffle(Prioq *q, void *data, unsigned *idx);
-void *prioq_peek(Prioq *q);
+void *prioq_peek(Prioq *q) _pure_;
void *prioq_pop(Prioq *q);
-unsigned prioq_size(Prioq *q);
-bool prioq_isempty(Prioq *q);
+unsigned prioq_size(Prioq *q) _pure_;
+bool prioq_isempty(Prioq *q) _pure_;
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index 33838345ed..7829a337fc 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -67,9 +67,9 @@ typedef enum SocketAddressBindIPv6Only {
int socket_address_parse(SocketAddress *a, const char *s);
int socket_address_parse_netlink(SocketAddress *a, const char *s);
int socket_address_print(const SocketAddress *a, char **p);
-int socket_address_verify(const SocketAddress *a);
+int socket_address_verify(const SocketAddress *a) _pure_;
-bool socket_address_can_accept(const SocketAddress *a);
+bool socket_address_can_accept(const SocketAddress *a) _pure_;
int socket_address_listen(
const SocketAddress *a,
@@ -90,12 +90,12 @@ bool socket_address_matches_fd(const SocketAddress *a, int fd);
int make_socket_fd(const char* address, int flags);
-bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
+bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) _pure_;
bool socket_address_needs_mount(const SocketAddress *a, const char *prefix);
-const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b);
-SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s);
+const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b) _const_;
+SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s) _pure_;
int netlink_family_to_string_alloc(int b, char **s);
int netlink_family_from_string(const char *s);
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 73ee416b1b..e35118752f 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -26,8 +26,8 @@
#include "macro.h"
-char *strv_find(char **l, const char *name);
-char *strv_find_prefix(char **l, const char *name);
+char *strv_find(char **l, const char *name) _pure_;
+char *strv_find_prefix(char **l, const char *name) _pure_;
void strv_free(char **l);
static inline void strv_freep(char ***l) {
@@ -37,7 +37,7 @@ static inline void strv_freep(char ***l) {
#define _cleanup_strv_free_ _cleanup_(strv_freep)
char **strv_copy(char * const *l);
-unsigned strv_length(char * const *l);
+unsigned strv_length(char * const *l) _pure_;
char **strv_merge(char **a, char **b);
char **strv_merge_concat(char **a, char **b, const char *suffix);
@@ -71,7 +71,7 @@ char *strv_join(char **l, const char *separator);
char **strv_parse_nulstr(const char *s, size_t l);
char **strv_split_nulstr(const char *s);
-bool strv_overlap(char **a, char **b);
+bool strv_overlap(char **a, char **b) _pure_;
#define STRV_FOREACH(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 3fc339507c..f27a006891 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -66,10 +66,10 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u);
#define dual_timestamp_is_set(ts) ((ts)->realtime > 0)
-usec_t timespec_load(const struct timespec *ts);
+usec_t timespec_load(const struct timespec *ts) _pure_;
struct timespec *timespec_store(struct timespec *ts, usec_t u);
-usec_t timeval_load(const struct timeval *tv);
+usec_t timeval_load(const struct timeval *tv) _pure_;
struct timeval *timeval_store(struct timeval *tv, usec_t u);
char *format_timestamp(char *buf, size_t l, usec_t t);
diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h
index c28d55d3e8..9eca8eb3c1 100644
--- a/src/shared/unit-name.h
+++ b/src/shared/unit-name.h
@@ -23,6 +23,8 @@
#include <stdbool.h>
+#include "macro.h"
+
#define UNIT_NAME_MAX 256
typedef enum UnitType UnitType;
@@ -53,21 +55,21 @@ enum UnitLoadState {
_UNIT_LOAD_STATE_INVALID = -1
};
-const char *unit_type_to_string(UnitType i);
-UnitType unit_type_from_string(const char *s);
+const char *unit_type_to_string(UnitType i) _const_;
+UnitType unit_type_from_string(const char *s) _pure_;
-const char *unit_load_state_to_string(UnitLoadState i);
-UnitLoadState unit_load_state_from_string(const char *s);
+const char *unit_load_state_to_string(UnitLoadState i) _const_;
+UnitLoadState unit_load_state_from_string(const char *s) _pure_;
int unit_name_to_instance(const char *n, char **instance);
char* unit_name_to_prefix(const char *n);
char* unit_name_to_prefix_and_instance(const char *n);
-bool unit_name_is_valid(const char *n, bool template_ok);
-bool unit_prefix_is_valid(const char *p);
-bool unit_instance_is_valid(const char *i);
+bool unit_name_is_valid(const char *n, bool template_ok) _pure_;
+bool unit_prefix_is_valid(const char *p) _pure_;
+bool unit_instance_is_valid(const char *i) _pure_;
-UnitType unit_name_to_type(const char *n);
+UnitType unit_name_to_type(const char *n) _pure_;
char *unit_name_change_suffix(const char *n, const char *suffix);
@@ -78,8 +80,8 @@ char *unit_name_unescape(const char *f);
char *unit_name_path_escape(const char *f);
char *unit_name_path_unescape(const char *f);
-bool unit_name_is_template(const char *n);
-bool unit_name_is_instance(const char *n);
+bool unit_name_is_template(const char *n) _pure_;
+bool unit_name_is_instance(const char *n) _pure_;
char *unit_name_replace_instance(const char *f, const char *i);
diff --git a/src/shared/util.c b/src/shared/util.c
index f9ec14aff4..5d01802ed9 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1449,7 +1449,7 @@ char *ascii_strlower(char *t) {
return t;
}
-static bool ignore_file_allow_backup(const char *filename) {
+_pure_ static bool ignore_file_allow_backup(const char *filename) {
assert(filename);
return
@@ -1512,7 +1512,7 @@ int fd_cloexec(int fd, bool cloexec) {
return 0;
}
-static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
+_pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
unsigned i;
assert(n_fdset == 0 || fdset);
@@ -2770,7 +2770,7 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
return ret;
}
-static int is_temporary_fs(struct statfs *s) {
+_pure_ static int is_temporary_fs(struct statfs *s) {
assert(s);
return
F_TYPE_CMP(s->f_type, TMPFS_MAGIC) ||
diff --git a/src/shared/util.h b/src/shared/util.h
index eb82ff4197..0bcda48b6d 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -74,7 +74,7 @@ size_t page_size(void);
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
-bool streq_ptr(const char *a, const char *b);
+bool streq_ptr(const char *a, const char *b) _pure_;
#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n)))
@@ -106,17 +106,17 @@ static inline bool isempty(const char *p) {
return !p || !p[0];
}
-char *endswith(const char *s, const char *postfix);
-char *startswith(const char *s, const char *prefix);
-char *startswith_no_case(const char *s, const char *prefix);
+char *endswith(const char *s, const char *postfix) _pure_;
+char *startswith(const char *s, const char *prefix) _pure_;
+char *startswith_no_case(const char *s, const char *prefix) _pure_;
-bool first_word(const char *s, const char *word);
+bool first_word(const char *s, const char *word) _pure_;
int close_nointr(int fd);
void close_nointr_nofail(int fd);
void close_many(const int fds[], unsigned n_fd);
-int parse_boolean(const char *v);
+int parse_boolean(const char *v) _pure_;
int parse_bytes(const char *t, off_t *bytes);
int parse_pid(const char *s, pid_t* ret_pid);
int parse_uid(const char *s, uid_t* ret_uid);
@@ -230,12 +230,12 @@ char *bus_path_unescape(const char *s);
char *ascii_strlower(char *path);
-bool dirent_is_file(const struct dirent *de);
-bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix);
+bool dirent_is_file(const struct dirent *de) _pure_;
+bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_;
-bool ignore_file(const char *filename);
+bool ignore_file(const char *filename) _pure_;
-bool chars_intersect(const char *a, const char *b);
+bool chars_intersect(const char *a, const char *b) _pure_;
int make_stdio(int fd);
int make_null_stdio(void);
@@ -307,7 +307,7 @@ bool fstype_is_network(const char *fstype);
int chvt(int vt);
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
-int ask(char *ret, const char *replies, const char *text, ...);
+int ask(char *ret, const char *replies, const char *text, ...) _printf_attr_(3, 4);
int reset_terminal_fd(int fd, bool switch_to_text);
int reset_terminal(const char *name);
@@ -388,7 +388,7 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid);
_noreturn_ void freeze(void);
-bool null_or_empty(struct stat *st);
+bool null_or_empty(struct stat *st) _pure_;
int null_or_empty_path(const char *fn);
DIR *xopendirat(int dirfd, const char *name, int flags);
@@ -398,7 +398,7 @@ char *fstab_node_to_udev_node(const char *p);
char *resolve_dev_console(char **active);
bool tty_is_vc(const char *tty);
bool tty_is_vc_resolve(const char *tty);
-bool tty_is_console(const char *tty);
+bool tty_is_console(const char *tty) _pure_;
int vtnr_from_tty(const char *tty);
const char *default_term_for_tty(const char *tty);
@@ -410,7 +410,7 @@ bool nulstr_contains(const char*nulstr, const char *needle);
bool plymouth_running(void);
-bool hostname_is_valid(const char *s);
+bool hostname_is_valid(const char *s) _pure_;
char* hostname_cleanup(char *s);
char* strshorten(char *s, size_t l);
@@ -426,7 +426,7 @@ int symlink_atomic(const char *from, const char *to);
int fchmod_umask(int fd, mode_t mode);
-bool display_is_local(const char *display);
+bool display_is_local(const char *display) _pure_;
int socket_from_display(const char *display, char **path);
int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home, const char **shell);
@@ -449,7 +449,7 @@ char *strjoin(const char *x, ...) _sentinel_;
bool is_main_thread(void);
-bool in_charset(const char *s, const char* charset);
+bool in_charset(const char *s, const char* charset) _pure_;
int block_get_whole_disk(dev_t d, dev_t *ret);
@@ -466,8 +466,8 @@ int strdup_or_null(const char *a, char **b);
int ioprio_class_to_string_alloc(int i, char **s);
int ioprio_class_from_string(const char *s);
-const char *sigchld_code_to_string(int i);
-int sigchld_code_from_string(const char *s);
+const char *sigchld_code_to_string(int i) _const_;
+int sigchld_code_from_string(const char *s) _pure_;
int log_facility_unshifted_to_string_alloc(int i, char **s);
int log_facility_unshifted_from_string(const char *s);
@@ -478,14 +478,14 @@ int log_level_from_string(const char *s);
int sched_policy_to_string_alloc(int i, char **s);
int sched_policy_from_string(const char *s);
-const char *rlimit_to_string(int i);
-int rlimit_from_string(const char *s);
+const char *rlimit_to_string(int i) _const_;
+int rlimit_from_string(const char *s) _pure_;
int ip_tos_to_string_alloc(int i, char **s);
int ip_tos_from_string(const char *s);
-const char *signal_to_string(int i);
-int signal_from_string(const char *s);
+const char *signal_to_string(int i) _const_;
+int signal_from_string(const char *s) _pure_;
int signal_from_string_try_harder(const char *s);
@@ -494,7 +494,7 @@ extern char **saved_argv;
bool kexec_loaded(void);
-int prot_from_flags(int flags);
+int prot_from_flags(int flags) _const_;
char *format_bytes(char *buf, size_t l, off_t t);
@@ -516,7 +516,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value);
int can_sleep(const char *type);
int can_sleep_disk(const char *type);
-bool is_valid_documentation_url(const char *url);
+bool is_valid_documentation_url(const char *url) _pure_;
bool in_initrd(void);
@@ -574,10 +574,10 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
return memdup(p, a * b);
}
-bool filename_is_safe(const char *p);
-bool path_is_safe(const char *p);
-bool string_is_safe(const char *p);
-bool string_has_cc(const char *p);
+bool filename_is_safe(const char *p) _pure_;
+bool path_is_safe(const char *p) _pure_;
+bool string_is_safe(const char *p) _pure_;
+bool string_has_cc(const char *p) _pure_;
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
int (*compar) (const void *, const void *, void *),
@@ -734,4 +734,4 @@ static inline void _reset_locale_(struct _locale_struct_ *s) {
!_saved_locale_.quit; }) ; \
_saved_locale_.quit = true)
-bool id128_is_valid(const char *s);
+bool id128_is_valid(const char *s) _pure_;
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 342e0a9cf1..5d88405e13 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -190,7 +190,7 @@ int utmp_put_reboot(usec_t t) {
return write_entry_both(&store);
}
-static const char *sanitize_id(const char *id) {
+_pure_ static const char *sanitize_id(const char *id) {
size_t l;
assert(id);
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 4c9c149a2d..461a7261f4 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -150,7 +150,7 @@ static void warn_wall(usec_t n, struct sd_shutdown_command *c) {
}
}
-static usec_t when_wall(usec_t n, usec_t elapse) {
+_const_ static usec_t when_wall(usec_t n, usec_t elapse) {
static const struct {
usec_t delay;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 6067781cf1..f9a03cad0d 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5414,7 +5414,7 @@ static int parse_argv(int argc, char *argv[]) {
return systemctl_parse_argv(argc, argv);
}
-static int action_to_runlevel(void) {
+_pure_ static int action_to_runlevel(void) {
static const char table[_ACTION_MAX] = {
[ACTION_HALT] = '0',