chiark / gitweb /
missing.h : add bridge params
[elogind.git] / src / basic / util.h
index 200f3befe86eb64c6bdf573cab873f0398974a44..2fde4282108b706facc62f6491fecc1104617b14 100644 (file)
@@ -41,6 +41,7 @@
 #include <mntent.h>
 #include <sys/inotify.h>
 #include <sys/statfs.h>
+#include <sys/sysmacros.h>
 
 #include "macro.h"
 #include "missing.h"
@@ -286,9 +287,9 @@ bool chars_intersect(const char *a, const char *b) _pure_;
 
 ssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
 
-#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)                                \
-        scope inline type name##_from_string(const char *s) {                                   \
-                return (type)string_table_lookup(name##_table, ELEMENTSOF(name##_table), s);    \
+#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)        \
+        scope type name##_from_string(const char *s) {                  \
+                return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
         }
 
 #define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope)                    \
@@ -305,17 +306,15 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
 #define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max)         \
         int name##_to_string_alloc(type i, char **str) {                \
                 char *s;                                                \
-                int r;                                                  \
                 if (i < 0 || i > max)                                   \
                         return -ERANGE;                                 \
                 if (i < (type) ELEMENTSOF(name##_table)) {              \
                         s = strdup(name##_table[i]);                    \
                         if (!s)                                         \
-                                return log_oom();                       \
+                                return -ENOMEM;                         \
                 } else {                                                \
-                        r = asprintf(&s, "%i", i);                      \
-                        if (r < 0)                                      \
-                                return log_oom();                       \
+                        if (asprintf(&s, "%i", i) < 0)                  \
+                                return -ENOMEM;                         \
                 }                                                       \
                 *str = s;                                               \
                 return 0;                                               \
@@ -323,10 +322,10 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
         type name##_from_string(const char *s) {                        \
                 type i;                                                 \
                 unsigned u = 0;                                         \
-                assert(s);                                              \
-                for (i = 0; i < (type)ELEMENTSOF(name##_table); i++)    \
-                        if (name##_table[i] &&                          \
-                            streq(name##_table[i], s))                  \
+                if (!s)                                                 \
+                        return (type) -1;                               \
+                for (i = 0; i < (type) ELEMENTSOF(name##_table); i++)   \
+                        if (streq_ptr(name##_table[i], s))              \
                                 return i;                               \
                 if (safe_atou(s, &u) >= 0 && u <= max)                  \
                         return (type) u;                                \
@@ -375,7 +374,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
 
 int files_same(const char *filea, const char *fileb);
 
-// UNNEEDED int running_in_chroot(void);
+int running_in_chroot(void);
 
 char *ellipsize(const char *s, size_t length, unsigned percent);
                                    /* bytes                 columns */
@@ -890,7 +889,11 @@ union inotify_event_buffer {
         uint8_t raw[INOTIFY_EVENT_MAX];
 };
 
-#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
+#ifdef __GLIBC__
+ #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
+#else
+ #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), 0)
+#endif
 
 // UNNEEDED int ptsname_malloc(int fd, char **ret);
 
@@ -924,8 +927,8 @@ void sigkill_wait(pid_t *pid);
 
 // UNNEEDED int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
 
-char *shell_escape(const char *s, const char *bad);
-char *shell_maybe_quote(const char *s);
+// UNNEEDED char *shell_escape(const char *s, const char *bad);
+// UNNEEDED char *shell_maybe_quote(const char *s);
 
 int parse_mode(const char *s, mode_t *ret);