| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: optstr.9,v 1.5 2023/04/20 09:06:02 skrll Exp $ | | 1 | .\" $NetBSD: optstr.9,v 1.6 2023/04/20 10:43:17 uwe Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2006 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2006 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Julio M. Merino Vidal. | | 7 | .\" by Julio M. Merino Vidal. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -20,104 +20,136 @@ | | | @@ -20,104 +20,136 @@ |
20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | .\" POSSIBILITY OF SUCH DAMAGE. | | 28 | .\" POSSIBILITY OF SUCH DAMAGE. |
29 | .\" | | 29 | .\" |
30 | .Dd May 20, 2023 | | 30 | .Dd May 20, 2023 |
31 | .Dt OPTSTR 9 | | 31 | .Dt OPTSTR 9 |
32 | .Os | | 32 | .Os |
| | | 33 | . |
33 | .Sh NAME | | 34 | .Sh NAME |
34 | .Nm optstr_get , | | 35 | .Nm optstr_get , |
35 | .Nm optstr_get_string , | | 36 | .Nm optstr_get_string , |
36 | .Nm optstr_get_number , | | 37 | .Nm optstr_get_number , |
37 | .Nm optstr_get_number_binary , | | 38 | .Nm optstr_get_number_binary , |
38 | .Nm optstr_get_number_hex , | | 39 | .Nm optstr_get_number_hex , |
39 | .Nm optstr_get_macaddr | | 40 | .Nm optstr_get_macaddr |
40 | .Nd Options string management | | 41 | .Nd Options string management |
| | | 42 | . |
41 | .Sh SYNOPSIS | | 43 | .Sh SYNOPSIS |
42 | .In sys/optstr.h | | 44 | .In sys/optstr.h |
| | | 45 | . |
43 | .Ft bool | | 46 | .Ft bool |
44 | .Fn optstr_get "const char *optstr" "const char *key" "char *buf" "size_t bufsize" | | 47 | .Fo optstr_get |
45 | .Ft bool | | 48 | .Fa "const char *optstr" |
46 | .Fn optstr_get_string "const char *optstr" "const char *key" "char **result" | | 49 | .Fa "const char *key" |
47 | .Ft bool | | 50 | .Fa "char *buf" |
48 | .Fn optstr_get_number "const char *optstr" "const char *key" "unsigned long *result" | | 51 | .Fa "size_t bufsize" |
49 | .Ft bool | | 52 | .Fc |
50 | .Fn optstr_get_number_binary "const char *optstr" "const char *key" "unsigned long *result" | | 53 | . |
51 | .Ft bool | | 54 | .Ft bool |
52 | .Fn optstr_get_number_hex "const char *optstr" "const char *key" "unsigned long *result" | | 55 | .Fo optstr_get_string |
53 | .Ft bool | | 56 | .Fa "const char *optstr" |
54 | .Fn optstr_get_macaddr "const char *optstr" "const char *key" "uint8_t result[ETHER_ADDR_LEN]" | | 57 | .Fa "const char *key" |
| | | 58 | .Fa "char **result" |
| | | 59 | .Fc |
| | | 60 | . |
| | | 61 | .Ft bool |
| | | 62 | .Fo optstr_get_number |
| | | 63 | .Fa "const char *optstr" |
| | | 64 | .Fa "const char *key" |
| | | 65 | .Fa "unsigned long *result" |
| | | 66 | .Fc |
| | | 67 | . |
| | | 68 | .Ft bool |
| | | 69 | .Fo optstr_get_number_binary |
| | | 70 | .Fa "const char *optstr" |
| | | 71 | .Fa "const char *key" |
| | | 72 | .Fa "unsigned long *result" |
| | | 73 | .Fc |
| | | 74 | . |
| | | 75 | .Ft bool |
| | | 76 | .Fo optstr_get_number_hex |
| | | 77 | .Fa "const char *optstr" |
| | | 78 | .Fa "const char *key" |
| | | 79 | .Fa "unsigned long *result" |
| | | 80 | .Fc |
| | | 81 | . |
| | | 82 | .Ft bool |
| | | 83 | .Fo optstr_get_macaddr |
| | | 84 | .Fa "const char *optstr" |
| | | 85 | .Fa "const char *key" |
| | | 86 | .Fa "uint8_t result[ETHER_ADDR_LEN]" |
| | | 87 | .Fc |
| | | 88 | . |
55 | .Sh DESCRIPTION | | 89 | .Sh DESCRIPTION |
56 | An options string is a list of key/value pairs represented in textual form. | | 90 | An options string is a list of key/value pairs represented in textual form. |
57 | Each pair is expressed as | | 91 | Each pair is expressed as |
58 | .Sq 'key=value' | | 92 | .Ar key\^ Ns Li = Ns Ar value |
59 | and is separated from other pairs by one or more spaces. | | 93 | and is separated from other pairs by one or more spaces. |
60 | For example: | | 94 | For example: |
61 | .Bd -literal | | 95 | .Pp |
62 | key1=value1 key2=value2 key3=value3 | | 96 | .Dl key1=value1 key2=value2 key3=value3 |
63 | .Ed | | | |
64 | .Pp | | 97 | .Pp |
65 | Options strings are used to pass information between userland programs and | | 98 | Options strings are used to pass information between userland programs and |
66 | the kernel in a binary-agnostic way. | | 99 | the kernel in a binary-agnostic way. |
67 | This makes them endianness and ABI independent. | | 100 | This makes them endianness and ABI independent. |
68 | .Sh FUNCTIONS | | 101 | .Sh FUNCTIONS |
69 | The following functions are provided to manage options strings: | | 102 | The following functions are provided to manage options strings: |
70 | .Bl -tag -width compact | | 103 | .Bl -tag -width Fn |
71 | .It Fn optstr_get "optstr" "key" "buf" "bufsize" | | 104 | .It Fn optstr_get "optstr" "key" "buf" "bufsize" |
72 | Scans the | | 105 | Scans the |
73 | .Va optstr | | 106 | .Fa optstr |
74 | options string looking for the key | | 107 | options string looking for the key |
75 | .Va key | | 108 | .Fa key |
76 | and stores its value in the buffer pointed to by | | 109 | and stores its value in the buffer pointed to by |
77 | .Va buf | | 110 | .Fa buf |
78 | copying a maximum of | | 111 | copying a maximum of |
79 | .Va bufsize | | 112 | .Fa bufsize |
80 | bytes. | | 113 | bytes. |
81 | Returns | | 114 | Returns |
82 | .Sq true | | 115 | .Ql true |
83 | if the key was found or | | 116 | if the key was found or |
84 | .Sq false | | 117 | .Ql false |
85 | otherwise, in which case | | 118 | otherwise, in which case |
86 | .Va buf | | 119 | .Fa buf |
87 | is left unmodified. | | 120 | is left unmodified. |
88 | .El | | 121 | .El |
89 | .Pp | | 122 | .Pp |
90 | The | | 123 | The |
91 | .Fn optstr_get_ITEM | | 124 | .Li optstr_get_ Ns Ar item |
92 | family of functions provide the ability to scan for the key, and | | 125 | family of functions provide the ability to scan for the key, and |
93 | return the value converted to an appropriate type. | | 126 | return the value converted to an appropriate type. |
94 | .Pp | | 127 | .Pp |
95 | .Bl -tag -width compact | | 128 | .Bl -tag -width Fn -compact |
96 | .It Fn optstr_get_string "optstr" "key" "result" | | 129 | .It Fn optstr_get_string "optstr" "key" "result" |
97 | .It Fn optstr_get_number "optstr" "key" "result" | | 130 | .It Fn optstr_get_number "optstr" "key" "result" |
98 | .It Fn optstr_get_number_binary "optstr" "key" "result" | | 131 | .It Fn optstr_get_number_binary "optstr" "key" "result" |
99 | .It Fn optstr_get_number_hex "optstr" "key" "result" | | 132 | .It Fn optstr_get_number_hex "optstr" "key" "result" |
100 | .It Fn optstr_get_macaddr "optstr" "key" "result" | | 133 | .It Fn optstr_get_macaddr "optstr" "key" "result" |
101 | .Pp | | | |
102 | These functions scan the | | 134 | These functions scan the |
103 | .Va optstr | | 135 | .Fa optstr |
104 | options string looking for the key | | 136 | options string looking for the key |
105 | .Va key | | 137 | .Fa key |
106 | and returns the key value converted as per the function name in | | 138 | and returns the key value converted as per the function name in |
107 | .Va result . | | 139 | .Fa result . |
108 | All functions return | | 140 | All functions return |
109 | .Sq true | | 141 | .Ql true |
110 | if the key was found or | | 142 | if the key was found or |
111 | .Sq false | | 143 | .Ql false |
112 | otherwise, in which case | | 144 | otherwise, in which case |
113 | .Va result | | 145 | .Fa result |
114 | is left unmodified. | | 146 | is left unmodified. |
115 | .El | | 147 | .El |
116 | .Sh CODE REFERENCES | | 148 | .Sh CODE REFERENCES |
117 | The options string management functions are implemented within the files | | 149 | The options string management functions are implemented within the files |
118 | .Pa sys/kern/subr_optstr.c | | 150 | .Pa sys/kern/subr_optstr.c |
119 | and | | 151 | and |
120 | .Pa sys/sys/optstr.h . | | 152 | .Pa sys/sys/optstr.h . |
121 | .Sh HISTORY | | 153 | .Sh HISTORY |
122 | Options strings appeared in | | 154 | Options strings appeared in |
123 | .Nx 4.0 . | | 155 | .Nx 4.0 . |