Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / core / env.c
blob2ec89602e6cef2a0c4f1304b1ff3b6e91465adb0
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <system.h>
22 #include <env.h>
24 env_t env_list;
26 void env_display ()
28 env_t *env;
29 for (env = env_list.next; env != &env_list; env = env->next)
30 printf ("%s=%s\n", env->name, env->value);
33 env_t *env_find (char *name)
35 if (!name)
36 return 0;
38 env_t *env;
39 for (env = env_list.next; env != &env_list; env = env->next) {
40 if (!strcmp (env->name, name))
41 return env;
44 return 0;
47 unsigned int env_set (char *name, char *value)
49 env_t *env = env_find (name);
51 if (env == 0)
52 return 0;
54 strcpy (env->value, value);
56 return 1;
59 char *env_get (char *name)
61 env_t *env = env_find (name);
63 if (env == 0)
64 return 0;
66 return env->value;
69 unsigned int env_create (char *name, char *value)
71 /* first check length of name and value */
72 if (strlen (name) >= DEFAULT_MAX_NAMELENGTH ||
73 strlen (value) >= DEFAULT_MAX_VALUELENGTH)
74 return 0;
76 /* env name havent to exists */
77 if (env_find (name) != 0)
78 return 0;
80 /* alloc and init context */
81 env_t *env = (env_t *) kmalloc (sizeof (env_t));
83 if (!env)
84 return 0;
86 strcpy (env->name, name);
87 strcpy (env->value, value);
89 /* add into list */
90 env->next = &env_list;
91 env->prev = env_list.prev;
92 env->prev->next = env;
93 env->next->prev = env;
95 DPRINT (DBG_CORE | DBG_ENV, "env_create () -> %s=%s", name, value);
97 return 1;
100 /* install all default env */
101 void env_install ()
103 env_create ("PWD", "/");
104 env_create ("HOME", "/");
105 env_create ("USER", "N/A");
106 env_create ("LANGUAGE", "en");
108 /* Keyboard layout */
109 if (keyboard_getlayout ("us"))
110 env_create ("KBD", "us");
111 if (keyboard_getlayout ("cz"))
112 env_create ("KBD", "cz");
115 unsigned int init_env ()
117 env_list.next = &env_list;
118 env_list.prev = &env_list;
120 // set default env values
121 env_list.name[0] = '\0';
122 env_list.value[0] = '\0';
124 env_install ();
126 return 1;