cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/2.25-lib-add-path_strdup.patch

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