2005-01-22 Marco Gerards <metgerards@student.han.nl>

* kern/misc.c (grub_strndup): Function rewritten.
This commit is contained in:
marco_g 2005-01-22 15:58:18 +00:00
parent 776bd7808d
commit e3741a2734
2 changed files with 14 additions and 9 deletions

View file

@ -1,3 +1,7 @@
2005-01-22 Marco Gerards <metgerards@student.han.nl>
* kern/misc.c (grub_strndup): Function rewritten.
2005-01-22 Vincent Pelletier <subdino2004@yahoo.fr> 2005-01-22 Vincent Pelletier <subdino2004@yahoo.fr>
* normal/menu.c (TERM_WIDTH): Macro redefined. * normal/menu.c (TERM_WIDTH): Macro redefined.

View file

@ -354,18 +354,19 @@ grub_strdup (const char *s)
char * char *
grub_strndup (const char *s, grub_size_t n) grub_strndup (const char *s, grub_size_t n)
{ {
grub_size_t len = 0; grub_size_t len;
char *p = (char *) s; char *p;
while (*(p++) && len < n) len = grub_strlen (s);
len++; if (len > n)
len = n;
len = grub_strlen (s) + 1; p = (char *) grub_malloc (len + 1);
p = (char *) grub_malloc (len);
if (! p) if (! p)
return 0; return 0;
return grub_memcpy (p, s, len); grub_memcpy (p, s, len);
p[len] = '\0';
return p;
} }
void * void *