/* envblk.c - Common functions for environment block. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 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 <config.h>
{
if (size < sizeof (GRUB_ENVBLK_SIGNATURE)
sizeof (GRUB_ENVBLK_SIGNATURE) - 1))
{
return 0;
}
if (envblk)
{
}
return envblk;
}
void
{
}
static int
{
int n = 0;
char *p;
for (p = (char *) value; *p; p++)
{
if (*p == '\\' || *p == '\n')
n += 2;
else
n++;
}
return n;
}
static char *
{
while (p < pend)
{
if (*p == '\\')
p += 2;
else if (*p == '\n')
break;
else
p++;
}
return p + 1;
}
int
{
char *p, *pend;
char *space;
int found = 0;
int nl;
int vl;
int i;
/* First, look at free space. */
;
if (*space != '\n')
/* Broken. */
return 0;
space++;
{
{
int len;
/* Found the same name. */
p += nl + 1;
/* Check the length of the current value. */
len = 0;
{
if (p[len] == '\\')
len += 2;
else
len++;
}
/* Broken. */
return 0;
/* No space. */
return 0;
{
/* Move the following characters backward, and fill the new
space with harmless characters. */
}
else
/* Move the following characters forward. */
found = 1;
break;
}
p = find_next_line (p, pend);
}
if (! found)
{
/* Append a new variable. */
/* No space. */
return 0;
*p++ = '=';
}
/* Write the value. */
for (i = 0; value[i]; i++)
{
*p++ = '\\';
*p++ = value[i];
}
*p = '\n';
return 1;
}
void
{
char *p, *pend;
int nl;
{
{
/* Found. */
{
if (p[len] == '\n')
break;
else if (p[len] == '\\')
len += 2;
else
len++;
}
/* Broken. */
return;
len++;
break;
}
p = find_next_line (p, pend);
}
}
void
{
char *p, *pend;
while (p < pend)
{
if (*p != '#')
{
char *name;
char *value;
char *q;
int ret;
name_start = p;
while (p < pend && *p != '=')
p++;
if (p == pend)
/* Broken. */
return;
name_end = p;
p++;
value_start = p;
while (p < pend)
{
if (*p == '\n')
break;
else if (*p == '\\')
p += 2;
else
p++;
}
if (p >= pend)
/* Broken. */
return;
if (! name)
/* out of memory. */
return;
{
if (*p == '\\')
*q++ = *++p;
else
*q++ = *p;
}
*q = '\0';
if (ret)
return;
}
p = find_next_line (p, pend);
}
}