[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] read command
From: |
Yoshinori K. Okuji |
Subject: |
Re: [PATCH] read command |
Date: |
Sat, 2 Feb 2008 13:38:28 +0100 |
User-agent: |
KMail/1.9.4 |
On Friday 01 February 2008 23:48, Robert Millan wrote:
> On Fri, Feb 01, 2008 at 11:45:50PM +0100, Robert Millan wrote:
> > +static void *
> > +grub_xrealloc (void *ptr, grub_size_t size)
> > +{
> > + void *value = grub_realloc (ptr, size);
> > + if (value == 0)
> > + grub_fatal ("Virtual memory exhausted");
> > + return value;
> > +}
> > +
> > +static char *
> > +grub_getline (void)
> > +{
> > + int i;
> > + char *line;
> > +
> > + i = 0;
> > + line = grub_malloc (1 + i + sizeof('\0'));
> > +
> > + while ((line[i - 1] != '\n') && (line[i - 1] != '\r'))
> > + {
> > + line[i] = grub_getkey ();
> > + if (grub_isprint (line[i]))
> > + grub_putchar (line[i]);
> > + i++;
> > + line = grub_xrealloc (line, 1 + i + sizeof('\0'));
> > + }
> > + line[i] = '\0';
> > +
> > + return line;
> > +}
>
> Does it make sense to move any of these two to kernel? Or to normal.mod ?
> Or maybe just to un-static-ize them and leave them here?
What would be other use cases?
BTW it is a bad idea to use xrealloc. xmalloc and xrealloc are sometimes used
in the GNU Project, but they must not be used in GRUB. If a program runs in
user space, when it panics, the control is back to the OS. But GRUB is a
standalone program. When it panics, the user loses any kind of control. Thus
grub_fatal must be used only if there is nothing else you can do.
In this case, grub_getline should simply return NULL. How the user deals with
this situation is up to the user.
Okuji