cdown / rpms / util-linux

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