replaced with grub_strchrsub function

This commit is contained in:
BVK Chaitanya 2010-11-25 18:56:20 +05:30
parent d7647bb670
commit 5b08062083
5 changed files with 31 additions and 28 deletions

View file

@ -228,7 +228,7 @@ setparams_prefix (int argc, char **args)
{
*p++ = ' ';
*p++ = '\'';
p = grub_script_escape_squotes (p, args[j], grub_strlen (args[j]));
p = grub_strchrsub (p, args[j], '\'', "'\\''");
*p++ = '\'';
}
*p++ = '\n';

View file

@ -323,16 +323,23 @@ struct legacy_command legacy_commands[] =
char *
grub_legacy_escape (const char *in, grub_size_t len)
{
const char *ptr;
char saved;
char *ptr;
char *outptr;
int overhead = 0;
for (ptr = in; ptr < in + len && *ptr; ptr++)
for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'')
overhead += 3;
outptr = grub_malloc (ptr - in + overhead + 1);
if (!outptr)
return NULL;
grub_script_escape_squotes (outptr, in, len);
ptr = (char*)in;
saved = ptr[len];
ptr[len] = '\0';
grub_strchrsub (outptr, in, '\'', "'\\''");
ptr[len] = saved;
return outptr;
}

View file

@ -22,27 +22,6 @@
#include <grub/parser.h>
#include <grub/mm.h>
/* Escape single quotes in first `len' characters of `in' into a GRUB
script argument form into `out'; return address of the end in
`out'. */
char *
grub_script_escape_squotes (char *out, const char *in, grub_size_t len)
{
while (*in && len--)
{
*out++ = *in;
if (*in == '\'')
{
*out++ = '\\';
*out++ = '\'';
*out++ = '\'';
}
in++;
}
*out = '\0';
return out;
}
/* It is not possible to deallocate the memory when a syntax error was
found. Because of that it is required to keep track of all memory
allocations. The memory is freed in case of an error, or assigned