Module Name: src
Committed By: jmcneill
Date: Sun May 28 23:31:41 UTC 2017
Modified Files:
src/sys/arch/arm/arm: bootconfig.c
src/sys/arch/arm/include: bootconfig.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/arm/bootconfig.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/include/bootconfig.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/arch/arm/arm/bootconfig.c
diff -u src/sys/arch/arm/arm/bootconfig.c:1.9 src/sys/arch/arm/arm/bootconfig.c:1.10
--- src/sys/arch/arm/arm/bootconfig.c:1.9 Wed Mar 2 19:25:32 2016
+++ src/sys/arch/arm/arm/bootconfig.c Sun May 28 23:31:41 2017
@@ -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 @@ get_bootconf_option(char *opts, const ch
}
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;
+}
Index: src/sys/arch/arm/include/bootconfig.h
diff -u src/sys/arch/arm/include/bootconfig.h:1.7 src/sys/arch/arm/include/bootconfig.h:1.8
--- src/sys/arch/arm/include/bootconfig.h:1.7 Tue Jan 6 00:43:21 2015
+++ src/sys/arch/arm/include/bootconfig.h Sun May 28 23:31:41 2017
@@ -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 @@ struct boot_physmem {
};
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 */