dcavalca / rpms / util-linux

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