/* env.c - Environment variables */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/env_private.h>
/* The initial context. */
/* The current context. */
/* Return the hash representation of the string S. */
static unsigned int
grub_env_hashval (const char *s)
{
unsigned int i = 0;
/* XXX: This can be done much more efficiently. */
while (*s)
i += 5 * *(s++);
return i % HASHSZ;
}
struct grub_env_var *
{
/* Look for the variable in the current context. */
return var;
return 0;
}
static void
struct grub_env_var *var)
{
/* Insert the variable into the hashtable. */
}
static void
{
/* Remove the entry from the variable table. */
}
{
/* If the variable does already exist, just update the variable. */
if (var)
{
if (var->write_hook)
else
{
return grub_errno;
}
return GRUB_ERR_NONE;
}
/* The variable does not exist, so create a new one. */
if (! var)
return grub_errno;
/* This is not necessary. But leave this for readability. */
goto fail;
goto fail;
return GRUB_ERR_NONE;
fail:
return grub_errno;
}
const char *
{
if (! var)
return 0;
}
void
{
if (! var)
return;
{
return;
}
}
void
{
int i;
/* Add variables associated with this context into a sorted list. */
for (i = 0; i < HASHSZ; i++)
{
{
struct grub_env_sorted_var *p, **q;
if (! sorted_var)
goto fail;
for (q = &sorted_list, p = *q; p; q = &((*q)->next), p = *q)
{
break;
}
sorted_var->next = *q;
*q = sorted_var;
}
}
/* Iterate FUNC on the sorted list. */
break;
fail:
/* Free the sorted list. */
{
sorted_var = tmp;
}
}
{
if (! var)
{
return grub_errno;
/* XXX Insert an assertion? */
}
return GRUB_ERR_NONE;
}
{
if (! var)
{
if (err)
return err;
}
return GRUB_ERR_NONE;
}