bug-gnulib
[Top][All Lists]
Advanced

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

Re: Fwd: Re: error.c: "Unknown system error" should report errno value (


From: Martin Koeppe
Subject: Re: Fwd: Re: error.c: "Unknown system error" should report errno value (fwd)
Date: Sat, 13 Oct 2007 22:51:14 +0200 (CEST)


On Sat, 13 Oct 2007, Bruno Haible wrote:

Martin Koeppe wrote:
The relevant output is done by asprintf(). And by printf() in line 269.

That's it. coreutils needs to use also printf-posix, not only vasprintf-posix.
Then 'seq' should work.

Or modify seq to not use printf() so that not every core-util on interix has a static copy of it, maybe as below. This works on interix. However, the plain printf(), at least the gnulib version, sometimes doesn't need malloc(), it uses vasnprintf() with a fixed buffer of 2000 chars. Only if that's not enough, malloc() is used. So this may be a reason to not use the patch below as is.


Martin


--- seq.c.orig  Thu Aug 16 14:25:11 2007
+++ seq.c       Sat Oct 13 22:24:53 2007
@@ -226,7 +226,10 @@
   for (i = 0; /* empty */; i++)
     {
       long double x = first + i * step;
-
+      char *x_str = NULL;
+      if (asprintf (&x_str, fmt, x) < 0)
+        xalloc_die();
+
       if (step < 0 ? x < last : last < x)
        {
          /* If we go one past the end, but that number prints the
@@ -238,10 +241,8 @@

          if (i)
            {
-             char *x_str = NULL;
              char *last_str = NULL;
-             if (asprintf (&x_str, fmt, x) < 0
-                 || asprintf (&last_str, fmt, last) < 0)
+             if (asprintf (&last_str, fmt, last) < 0)
                xalloc_die ();

              if (STREQ (x_str, last_str))
@@ -257,7 +258,6 @@
                  free (x0_str);
                }

-             free (x_str);
              free (last_str);
            }

@@ -266,7 +266,10 @@

       if (i)
        fputs (separator, stdout);
-      printf (fmt, x);
+
+      fputs (x_str, stdout);
+      free (x_str);
+
       x0 = x;
     }





reply via email to

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