Opened 4 years ago
Closed 4 years ago
#16259 closed bug (fixed)
asprintf was unexpectedly present during build
Reported by: | ddevault | Owned by: | korli |
---|---|---|---|
Priority: | normal | Milestone: | R1/beta3 |
Component: | System/POSIX | Version: | R1/beta2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
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.
Change History (5)
comment:2 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 4 years ago
Milestone: | Unscheduled → R1/beta3 |
---|
Note:
See TracTickets
for help on using tickets.
asprintf and vasprintf can be moved to headers/compatibility/bsd/stdio.h