AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
kargs.c
Go to the documentation of this file.
1
8
9#include <core/system.h>
10#include <core/string.h>
11#include <core/kargs.h>
12#include <aquila/errno.h>
13
14/* The most arguments that are kept; the rest are ignored. */
15#define MAX_ARGS 128
16
17static struct {
18 const char *key;
19 const char *value;
21
22static int kargc;
23
31int kargs_parse(const char *_cmdline)
32{
33 printk("kernel: cmdline: %s\n", _cmdline);
34
35 if (!_cmdline || !*_cmdline)
36 return 0;
37
38 char **tokens = tokenize(_cmdline, ' ');
39
40 /* no memory for the arguments: the kernel goes on without them */
41 if (!tokens)
42 return -ENOMEM;
43
44 for (char **token_p = tokens; *token_p && kargc < MAX_ARGS; ++token_p) {
45 char *token = *token_p;
46
47 kargs[kargc].key = token;
48 kargs[kargc].value = NULL;
49
50 /* split on the first '=' only: the value may contain '=' too */
51 for (char *c = token; *c; ++c) {
52 if (*c == '=') {
53 *c = 0;
54 kargs[kargc].value = c + 1;
55 break;
56 }
57 }
58
59 ++kargc;
60 }
61
62 return kargc;
63}
64
73int kargs_get(const char *key, const char **value)
74{
75 for (int i = 0; i < kargc; ++i) {
76 if (!strcmp(kargs[i].key, key)) {
77 if (value)
78 *value = kargs[i].value;
79
80 return 0;
81 }
82 }
83
84 return -1;
85}
#define MAX_ARGS
Definition kargs.c:15
static struct @004075361110374343276033126231304077040270253326 kargs[MAX_ARGS]
int kargs_get(const char *key, const char **value)
Looks up an argument of the kernel's command line.
Definition kargs.c:73
static int kargc
Definition kargs.c:22
int kargs_parse(const char *_cmdline)
Splits the kernel's command line into arguments, at boot.
Definition kargs.c:31
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
Definition printk.c:249
#define NULL
Definition stddef.h:27
const char * value
const char * key