Module Name:    src
Committed By:   riastradh
Date:           Mon Aug 27 06:46:56 UTC 2018

Modified Files:
        src/sys/external/bsd/common/include/linux: kernel.h

Log Message:
Implement Linux kasprintf.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/common/include/linux/kernel.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/common/include/linux/kernel.h
diff -u src/sys/external/bsd/common/include/linux/kernel.h:1.13 src/sys/external/bsd/common/include/linux/kernel.h:1.14
--- src/sys/external/bsd/common/include/linux/kernel.h:1.13	Mon Aug 27 06:15:32 2018
+++ src/sys/external/bsd/common/include/linux/kernel.h	Mon Aug 27 06:46:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernel.h,v 1.13 2018/08/27 06:15:32 riastradh Exp $	*/
+/*	$NetBSD: kernel.h,v 1.14 2018/08/27 06:46:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 #include <lib/libkern/libkern.h>
 #include <linux/bitops.h>
 #include <linux/printk.h>
+#include <linux/slab.h>
 
 #define U16_MAX UINT16_MAX
 #define U32_MAX UINT32_MAX
@@ -179,4 +180,28 @@ kstrtol(const char *s, unsigned base, lo
 	return 0;
 }
 
+static inline char * __printflike(2,3)
+kasprintf(gfp_t gfp, const char *fmt, ...)
+{
+	va_list va;
+	char *str;
+	int len, len1 __diagused;
+
+	va_start(va, fmt);
+	len = vsnprintf(NULL, 0, fmt, va);
+	va_end(va);
+
+	str = kmalloc(len + 1, gfp);
+	if (str == NULL)
+		return NULL;
+
+	va_start(va, fmt);
+	len1 = vsnprintf(str, len + 1, fmt, va);
+	va_end(va);
+
+	KASSERT(len1 == len);
+
+	return str;
+}
+
 #endif  /* _LINUX_KERNEL_H_ */

Reply via email to