05ad79
From dd3bc51a539ffdd5c6c6b7d0b20acd1f61bdd337 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Mon, 6 Jan 2014 16:48:13 +0100
05ad79
Subject: [PATCH] lib/path: add path_strdup()
05ad79
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 include/path.h |  2 ++
05ad79
 lib/path.c     | 13 +++++++++++++
05ad79
 2 files changed, 15 insertions(+)
05ad79
05ad79
diff --git a/include/path.h b/include/path.h
05ad79
index 615d284..45da692 100644
05ad79
--- a/include/path.h
05ad79
+++ b/include/path.h
05ad79
@@ -4,6 +4,8 @@
05ad79
 #include <stdio.h>
05ad79
 #include <stdint.h>
05ad79
 
05ad79
+extern char *path_strdup(const char *path, ...)
05ad79
+			__attribute__ ((__format__ (__printf__, 1, 2)));
05ad79
 extern FILE *path_fopen(const char *mode, int exit_on_err, const char *path, ...)
05ad79
 			__attribute__ ((__format__ (__printf__, 3, 4)));
05ad79
 extern void path_read_str(char *result, size_t len, const char *path, ...)
05ad79
diff --git a/lib/path.c b/lib/path.c
05ad79
index 1f7e258..42d321c 100644
05ad79
--- a/lib/path.c
05ad79
+++ b/lib/path.c
05ad79
@@ -49,6 +49,19 @@ path_vcreate(const char *path, va_list ap)
05ad79
 	return pathbuf;
05ad79
 }
05ad79
 
05ad79
+char *
05ad79
+path_strdup(const char *path, ...)
05ad79
+{
05ad79
+	const char *p;
05ad79
+	va_list ap;
05ad79
+
05ad79
+	va_start(ap, path);
05ad79
+	p = path_vcreate(path, ap);
05ad79
+	va_end(ap);
05ad79
+
05ad79
+	return p ? strdup(p) : NULL;
05ad79
+}
05ad79
+
05ad79
 static FILE *
05ad79
 path_vfopen(const char *mode, int exit_on_error, const char *path, va_list ap)
05ad79
 {
05ad79
-- 
05ad79
1.8.4.2
05ad79