]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2005-01-22 Marco Gerards <metgerards@student.han.nl>
authormarco_g <marco_g@localhost>
Sat, 22 Jan 2005 15:58:18 +0000 (15:58 +0000)
committermarco_g <marco_g@localhost>
Sat, 22 Jan 2005 15:58:18 +0000 (15:58 +0000)
* kern/misc.c (grub_strndup): Function rewritten.

ChangeLog
kern/misc.c

index ce04f59aed255d3c860d0f7c4f91a30d374fbdfc..bcca1f81d5629393a301fa642effba2027df09b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * normal/menu.c (TERM_WIDTH): Macro redefined.
index 2015fb704e08884b145fdb51fef18b726377aab3..1352a6fe5a3bb418b2c7095efa935e82dbac6caf 100644 (file)
@@ -354,18 +354,19 @@ grub_strdup (const char *s)
 char *
 grub_strndup (const char *s, grub_size_t n)
 {
-  grub_size_t len = 0;
-  char *p = (char *) s;
+  grub_size_t len;
+  char *p;
   
-  while (*(p++) && len < n)
-    len++;
-
-  len = grub_strlen (s) + 1;
-  p = (char *) grub_malloc (len);
+  len = grub_strlen (s);
+  if (len > n)
+    len = n;
+  p = (char *) grub_malloc (len + 1);
   if (! p)
     return 0;
-
-  return grub_memcpy (p, s, len);
+  
+  grub_memcpy (p, s, len);
+  p[len] = '\0';
+  return p;
 }
 
 void *