Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm Add a few bootconfig helpers:



details:   https://anonhg.NetBSD.org/src/rev/f09bf9b6b07e
branches:  trunk
changeset: 353934:f09bf9b6b07e
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 28 23:31:41 2017 +0000

description:
Add a few bootconfig helpers:
 - get_bootconf_string: returns a copy of the "value" part of a k=v pair
     as a string.
 - match_bootconf_option: returns true if the "value" part of a k=v pair
     exists and the supplied val param is present in the beginning of the
     k=v pair's value.

diffstat:

 sys/arch/arm/arm/bootconfig.c     |  39 +++++++++++++++++++++++++++++++++++++--
 sys/arch/arm/include/bootconfig.h |   4 +++-
 2 files changed, 40 insertions(+), 3 deletions(-)

diffs (77 lines):

diff -r 9c16ad23a254 -r f09bf9b6b07e sys/arch/arm/arm/bootconfig.c
--- a/sys/arch/arm/arm/bootconfig.c     Sun May 28 22:37:36 2017 +0000
+++ b/sys/arch/arm/arm/bootconfig.c     Sun May 28 23:31:41 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootconfig.c,v 1.9 2016/03/02 19:25:32 christos Exp $  */
+/*     $NetBSD: bootconfig.c,v 1.10 2017/05/28 23:31:41 jmcneill Exp $ */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -40,9 +40,10 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: bootconfig.c,v 1.9 2016/03/02 19:25:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bootconfig.c,v 1.10 2017/05/28 23:31:41 jmcneill Exp $");
 
 #include <sys/systm.h>
+#include <sys/kmem.h>
 
 #include <machine/bootconfig.h>
 
@@ -145,3 +146,37 @@
        }
        return 0;
 }
+
+char *
+get_bootconf_string(char *opts, const char *key)
+{
+       char *s, *ret;
+       int i = 0;
+
+       if (!get_bootconf_option(opts, key, BOOTOPT_TYPE_STRING, &s))
+               return NULL;
+
+       for (;;) {
+               if (s[i] == ' ' || s[i] == '\t' || s[i] == '\0')
+                       break;
+               ++i;
+       }
+
+       ret = kmem_alloc(i + 1, KM_SLEEP);
+       if (ret == NULL)
+               return NULL;
+
+       strlcpy(ret, s, i + 1);
+       return ret;
+}
+
+bool
+match_bootconf_option(char *opts, const char *key, const char *val)
+{
+       char *s;
+
+       if (!get_bootconf_option(opts, key, BOOTOPT_TYPE_STRING, &s))
+               return false;
+
+       return strncmp(s, val, strlen(val)) == 0;
+}
diff -r 9c16ad23a254 -r f09bf9b6b07e sys/arch/arm/include/bootconfig.h
--- a/sys/arch/arm/include/bootconfig.h Sun May 28 22:37:36 2017 +0000
+++ b/sys/arch/arm/include/bootconfig.h Sun May 28 23:31:41 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootconfig.h,v 1.7 2015/01/06 00:43:21 jmcneill Exp $  */
+/*     $NetBSD: bootconfig.h,v 1.8 2017/05/28 23:31:41 jmcneill Exp $  */
 
 /*
  * Copyright (c) 1994 Mark Brinicombe.
@@ -54,6 +54,8 @@
 };
 
 int get_bootconf_option(char *, const char *, int, void *);
+bool match_bootconf_option(char *, const char *, const char *);
+char *get_bootconf_string(char *, const char *);
 
 extern char *boot_args;
 #endif /* _KERNEL */



Home | Main Index | Thread Index | Old Index