Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/common/include/linux Add kvasprintf to <lin...



details:   https://anonhg.NetBSD.org/src/rev/aa5a677f5a1b
branches:  trunk
changeset: 365827:aa5a677f5a1b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 06:53:55 2018 +0000

description:
Add kvasprintf to <linux/kernel.h>.

diffstat:

 sys/external/bsd/common/include/linux/kernel.h |  31 +++++++++++++++----------
 1 files changed, 18 insertions(+), 13 deletions(-)

diffs (54 lines):

diff -r ff1d448049b8 -r aa5a677f5a1b sys/external/bsd/common/include/linux/kernel.h
--- a/sys/external/bsd/common/include/linux/kernel.h    Mon Aug 27 06:53:46 2018 +0000
+++ b/sys/external/bsd/common/include/linux/kernel.h    Mon Aug 27 06:53:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernel.h,v 1.14 2018/08/27 06:46:55 riastradh Exp $    */
+/*     $NetBSD: kernel.h,v 1.15 2018/08/27 06:53:55 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -180,27 +180,32 @@
        return 0;
 }
 
+static inline char *
+kvasprintf(gfp_t gfp, const char *fmt, va_list va)
+{
+       char *str;
+       int len, len1 __diagused;
+
+       len = vsnprintf(NULL, 0, fmt, va);
+       str = kmalloc(len + 1, gfp);
+       if (str == NULL)
+               return NULL;
+       len1 = vsnprintf(str, len + 1, fmt, va);
+       KASSERT(len1 == len);
+
+       return str;
+}
+
 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);
+       str = kvasprintf(gfp, 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;
 }
 



Home | Main Index | Thread Index | Old Index