Initial git release
[ZeXOS.git] / kernel / env.c
blob7057f95a0c6cbf65ba4603670cd6c36266e74ec0
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <env.h>
22 env_t env_list;
24 void env_display ()
26 env_t *env;
27 for (env = env_list.next; env != &env_list; env = env->next)
28 kprintf ("%s=%s\n", env->name, env->value);
31 env_t *env_find (char *name)
33 env_t *env;
34 for (env = env_list.next; env != &env_list; env = env->next) {
35 if (!strcmp (env->name, name))
36 return env;
39 return 0;
42 unsigned int env_set (char *name, char *value)
44 env_t *env = env_find (name);
46 if (env == 0)
47 return 0;
49 strcpy (env->value, value);
51 return 1;
54 char *env_get (char *name)
56 env_t *env = env_find (name);
58 if (env == 0)
59 return 0;
61 return env->value;
64 unsigned int env_create (char *name, char *value)
66 /* first check length of name and value */
67 if (strlen (name) >= DEFAULT_MAX_NAMELENGTH ||
68 strlen (value) >= DEFAULT_MAX_VALUELENGTH)
69 return 0;
71 /* env name havent to exists */
72 if (env_find (name) != 0)
73 return 0;
75 env_t *env;
77 /* alloc and init context */
78 env = (env_t *) kmalloc (sizeof (env_t));
80 strcpy (env->name, name);
81 strcpy (env->value, value);
83 /* add into list */
84 env->next = &env_list;
85 env->prev = env_list.prev;
86 env->prev->next = env;
87 env->next->prev = env;
89 DPRINT ("env_create () -> %s=%s", name, value);
91 return 1;
94 /* install all default env */
95 void env_install ()
97 env_create ("PWD", "/");
98 env_create ("HOME", "/");
99 env_create ("USER", "N/A");
100 env_create ("LANGUAGE", "en");
103 unsigned int init_env ()
105 env_list.next = &env_list;
106 env_list.prev = &env_list;
108 // set default env values
109 env_list.name[0] = '\0';
110 env_list.value[0] = '\0';
112 env_install ();
114 return 1;