bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] Re: [bug-report] could not generate stdbool.h and xstrndup.o


From: Yasutaka SHINDOH
Subject: [bug-patch] Re: [bug-report] could not generate stdbool.h and xstrndup.o
Date: Sat, 14 Nov 2009 10:07:34 +0900
User-agent: xcite1.58> Wanderlust/2.14.0 (Africa) EMIKO/1.14.1 (襟鞭毛虫) LIMIT/1.14.10 (古市) APEL/10.7 EasyPG/0.0.16 Emacs/22.3 (i486-apple-darwin9.8.0) MULE/5.0 (賢木)

Hi there,

>>>>> In message <address@hidden>
>>>>>   address@hidden wrote:

> GNU patch 2.6 has the following bugs.
> 
>       - could not generate gl/lib/stdbool.h
>       - could not compile gl/lib/xstrndup.c (Mac OS X)
> 
> ============================================================
[...]
> --- patch-2.6.orig/gl/lib/xstrndup.c    2009-11-14 08:35:31 +0900
> +++ patch-2.6/gl/lib/xstrndup.c 2009-11-14 08:35:11 +0900
> @@ -20,6 +20,7 @@
>  /* Specification.  */
>  #include "xstrndup.h"
>  
> +#include <stdlib.h>
>  #include <string.h>
>  #include "xalloc.h"
>  
> @@ -29,8 +30,12 @@
>  char *
>  xstrndup (const char *string, size_t n)
>  {
> -  char *s = strndup (string, n);
> -  if (! s)
> +  char *s = malloc(n);
> +  if (! s) {
>      xalloc_die ();
> +  }
> +  else {
> +    memcpy(s, string, n);
> +  }
>    return s;
>  }
> 
> ============================================================

Sorry, the above code is not good.
Please the following code.

============================================================

--- patch-2.6.orig/gl/lib/xstrndup.c    2009-11-14 09:54:03 +0900
+++ patch-2.6/gl/lib/xstrndup.c 2009-11-14 09:58:10 +0900
@@ -20,6 +20,7 @@
 /* Specification.  */
 #include "xstrndup.h"
 
+#include <stdlib.h>
 #include <string.h>
 #include "xalloc.h"
 
@@ -29,8 +30,18 @@
 char *
 xstrndup (const char *string, size_t n)
 {
-  char *s = strndup (string, n);
+  char *s = malloc(n+1);
+  size_t i;
   if (! s)
     xalloc_die ();
+  else {
+    for (i = 0; i < n; ++i) {
+      s[i] = string[i];
+      if (!string[i])
+       break;
+    }
+    if (i == n)
+      s[i] = '\0';
+  }
   return s;
 }

============================================================

-- 
Yasutaka SHINDOH ___ We will either find a way, or make one.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]