chiark / gitweb /
dbus: make data pointer for properties read-only
[elogind.git] / util.c
diff --git a/util.c b/util.c
index 3fe59c8ebba4b1a425bb0e4ee6bd2860d2715f9b..52ca5e25631a9e56f8fd5e27df7c63d777b6d50a 100644 (file)
--- a/util.c
+++ b/util.c
@@ -728,6 +728,20 @@ int mkdir_parents(const char *path, mode_t mode) {
         }
 }
 
+int mkdir_p(const char *path, mode_t mode) {
+        int r;
+
+        /* Like mkdir -p */
+
+        if ((r = mkdir_parents(path, mode)) < 0)
+                return r;
+
+        if (mkdir(path, mode) < 0)
+                return -errno;
+
+        return 0;
+}
+
 char hexchar(int x) {
         static const char table[16] = "0123456789abcdef";
 
@@ -1244,6 +1258,24 @@ bool chars_intersect(const char *a, const char *b) {
         return false;
 }
 
+char *format_timestamp(char *buf, size_t l, usec_t t) {
+        struct tm tm;
+        time_t sec;
+
+        assert(buf);
+        assert(l > 0);
+
+        if (t <= 0)
+                return NULL;
+
+        sec = (time_t) t / USEC_PER_SEC;
+
+        if (strftime(buf, l, "%a, %d %b %Y %H:%M:%S %z", localtime_r(&sec, &tm)) <= 0)
+                return NULL;
+
+        return buf;
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",