summaryrefslogtreecommitdiff
path: root/src/shared
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 /src/shared
parent2f79c10e9aef916efbcf29315eea8c25d0a50ac4 (diff)
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.
Diffstat (limited to 'src/shared')
-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
23 files changed, 118 insertions, 108 deletions
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);