chiark / gitweb /
core: add support for a configurable system-wide start-up timeout
[elogind.git] / src / shared / util.c
index a54e8799530d4e2e3b40161ef1c618c14b6109a7..fc6f668726c60ee7d00db1809b7e3f8a3f4de744 100644 (file)
@@ -7137,3 +7137,24 @@ int unquote_many_words(const char **p, ...) {
 
         return c;
 }
+
+int free_and_strdup(char **p, const char *s) {
+        char *t;
+
+        assert(p);
+
+        /* Replaces a string pointer with an strdup()ed new string,
+         * possibly freeing the old one. */
+
+        if (s) {
+                t = strdup(s);
+                if (!t)
+                        return -ENOMEM;
+        } else
+                t = NULL;
+
+        free(*p);
+        *p = t;
+
+        return 0;
+}