chiark / gitweb /
systemctl: add 'check' call
[elogind.git] / src / util.h
index 864d98fa635549f568f2f1d4365c6f20a16f2d01..eda8e5c406e4cb711f7dd95ba426f383e71ba57a 100644 (file)
 #include <stdio.h>
 #include <signal.h>
 
+#include "macro.h"
+
 typedef uint64_t usec_t;
 
-typedef struct timestamp {
+typedef struct dual_timestamp {
         usec_t realtime;
         usec_t monotonic;
-} timestamp;
+} dual_timestamp;
 
 #define MSEC_PER_SEC  1000ULL
 #define USEC_PER_SEC  1000000ULL
@@ -58,7 +60,7 @@ typedef struct timestamp {
 
 usec_t now(clockid_t clock);
 
-timestamp* timestamp_get(timestamp *ts);
+dual_timestamp* dual_timestamp_get(dual_timestamp *ts);
 
 usec_t timespec_load(const struct timespec *ts);
 struct timespec *timespec_store(struct timespec *ts, usec_t u);
@@ -113,6 +115,16 @@ int parse_pid(const char *s, pid_t* ret_pid);
 int safe_atou(const char *s, unsigned *ret_u);
 int safe_atoi(const char *s, int *ret_i);
 
+static inline int safe_atou32(const char *s, uint32_t *ret_u) {
+        assert_cc(sizeof(uint32_t) == sizeof(unsigned));
+        return safe_atou(s, (unsigned*) ret_u);
+}
+
+static inline int safe_atoi32(const char *s, int32_t *ret_u) {
+        assert_cc(sizeof(int32_t) == sizeof(int));
+        return safe_atoi(s, (int*) ret_u);
+}
+
 int safe_atolu(const char *s, unsigned long *ret_u);
 int safe_atoli(const char *s, long int *ret_i);
 
@@ -214,7 +226,8 @@ unsigned long long random_ull(void);
                 unsigned u = 0;                                         \
                 assert(s);                                              \
                 for (i = 0; i < (type)ELEMENTSOF(name##_table); i++)    \
-                        if (streq(name##_table[i], s))                  \
+                        if (name##_table[i] &&                          \
+                            streq(name##_table[i], s))                  \
                                 return i;                               \
                 if (safe_atou(s, &u) >= 0 &&                            \
                     u < ELEMENTSOF(name##_table))                       \
@@ -289,4 +302,7 @@ int sched_policy_from_string(const char *s);
 const char *rlimit_to_string(int i);
 int rlimit_from_string(const char *s);
 
+const char *ip_tos_to_string(int i);
+int ip_tos_from_string(const char *s);
+
 #endif