2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2016
7 * Jan Kiszka <jan.kiszka@siemens.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
15 extern const char cmdline[];
17 static bool get_param(const char *param, char *value_buffer,
18 unsigned long buffer_size)
20 unsigned long param_len = strlen(param);
21 const char *p = cmdline;
24 /* read over leading blanks */
28 if (strncmp(p, param, param_len) == 0) {
31 /* check for boolean parameter */
32 if ((buffer_size == 0 && (*p == ' ' || *p == 0)))
35 /* extract parameter value */
38 while (buffer_size > 1) {
39 if (*p == ' ' || *p == 0)
41 *value_buffer++ = *p++;
50 /* search for end of this parameter */
59 const char *cmdline_parse_str(const char *param, char *value_buffer,
60 unsigned long buffer_size,
61 const char *default_value)
63 if (get_param(param, value_buffer, buffer_size))
69 long long cmdline_parse_int(const char *param, long long default_value)
71 char value_buffer[32];
72 char *p = value_buffer;
73 bool negative = false;
76 if (!get_param(param, value_buffer, sizeof(value_buffer)))
79 if (strncmp(p, "0x", 2) == 0) {
82 if (*p >= '0' && *p <= '9')
83 value = (value << 4) + *p - '0';
84 else if (*p >= 'A' && *p <= 'F')
85 value = (value << 4) + *p - 'A' + 10;
86 else if (*p >= 'a' && *p <= 'f')
87 value = (value << 4) + *p - 'a' + 10;
93 if (*p == '-' || *p == '+')
94 negative = (*p++ == '-');
97 if (*p >= '0' && *p <= '9')
98 value = (value * 10) + *p - '0';
100 return default_value;
105 return negative ? -value : value;
108 bool cmdline_parse_bool(const char *param)
110 return get_param(param, NULL, 0);