chiark / gitweb /
Add gettext support
[elogind.git] / src / shared / util.c
index 3a633512473d7d7c93d0574ed9b27064490f7a3f..deb98396335acbe26ff4f3626c678747537739cd 100644 (file)
@@ -25,6 +25,8 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <libintl.h>
+#include <locale.h>
 #include <stdio.h>
 #include <syslog.h>
 #include <sched.h>
@@ -74,6 +76,7 @@
 #include <sys/auxv.h>
 #endif
 
+#include "config.h"
 #include "macro.h"
 #include "util.h"
 #include "ioprio.h"
@@ -5782,6 +5785,11 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
         return NULL;
 }
 
+void init_gettext(void) {
+        setlocale(LC_ALL, "");
+        textdomain(GETTEXT_PACKAGE);
+}
+
 bool is_locale_utf8(void) {
         const char *set;
         static int cached_answer = -1;
@@ -8089,3 +8097,16 @@ int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
         *p += k;
         return 1;
 }
+
+ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) {
+        size_t i;
+
+        if (!key)
+                return -1;
+
+        for (i = 0; i < len; ++i)
+                if (streq_ptr(table[i], key))
+                        return (ssize_t)i;
+
+        return -1;
+}