kernel: env support

This commit is contained in:
Matheus
2022-12-30 03:28:06 -03:00
parent bc7906bde4
commit 23f2ef05b9
2 changed files with 41 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
#ifndef _ENV_H_INCLUDE
#define _ENV_H_INCLUDE
#include <stdbool.h>
int env_set(const char*, const char*);
char* env_get(const char*);
bool env_isset(const char*);
void env_init();
#endif
+30
View File
@@ -0,0 +1,30 @@
#include <hashtable.h>
#include <errno.h>
#include <kernel/env.h>
#include <arch/panic.h>
static hashtable envtable;
int env_set(const char* name, const char* value){
if(!hashtable_set(&envtable, name, value))
if(!hashtable_insert(&envtable, name, value))
return ENOMEM;
return 0;
}
char* env_get(const char* name){
return hashtable_get(&envtable, name);
}
bool env_isset(const char* name){
return hashtable_isset(&envtable, name);
}
void env_init(){
if(!hashtable_init(&envtable, 50))
_panic("Out of memory!\n", NULL);
}