[haiku-bugs] [Haiku] #16259: asprintf was unexpectedly present during build

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Sun, 14 Jun 2020 23:11:44 -0000

#16259: asprintf was unexpectedly present during build
--------------------------+--------------------------
 Reporter:  ddevault      |       Owner:  nobody
     Type:  bug           |      Status:  new
 Priority:  normal        |   Milestone:  Unscheduled
Component:  System/POSIX  |     Version:  R1/beta2
 Keywords:                |  Blocked By:
 Blocking:                |    Platform:  All
--------------------------+--------------------------
 The following program, when compiled with "cc -std=c11 -o example
 example.c", produces an error: "error: static declaration of 'asprintf'
 follows non-static declaration"

 {{{
 #define _XOPEN_SOURCE 700
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>

 static int
 asprintf(char **strp, const char *fmt, ...)
 {
         va_list ap;
         va_start(ap, fmt);
         int n = vsnprintf(NULL, 0, fmt, ap);
         va_end(ap);

         *strp = calloc(n + 1, 1);
         if (!*strp) {
                 errno = ENOMEM;
                 return -1;
         }

         va_start(ap, fmt);
         n = vsnprintf(*strp, n + 1, fmt, ap);
         va_end(ap);
         return n;
 }

 int main(void) {
         return 0;
 }
 }}}

 asprintf is not specified by POSIX and a POSIX-compatible program is
 likely to implement it themselves. This should be gated behind a Haiku-
 specific environment variable, similar to the GNU approach via
 _DEFAULT_SOURCE or _GNU_SOURCE.
-- 
Ticket URL: <https://dev.haiku-os.org/ticket/16259>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: