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/>.
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
)
34 for (env
= env_list
.next
; env
!= &env_list
; env
= env
->next
) {
35 if (!strcmp (env
->name
, name
))
42 unsigned int env_set (char *name
, char *value
)
44 env_t
*env
= env_find (name
);
49 strcpy (env
->value
, value
);
54 char *env_get (char *name
)
56 env_t
*env
= env_find (name
);
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
)
71 /* env name havent to exists */
72 if (env_find (name
) != 0)
77 /* alloc and init context */
78 env
= (env_t
*) kmalloc (sizeof (env_t
));
80 strcpy (env
->name
, name
);
81 strcpy (env
->value
, value
);
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
);
94 /* install all default env */
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';