mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: env support
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user