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:1 by korli, 4 years ago

asprintf and vasprintf can be moved to headers/compatibility/bsd/stdio.h

Last edited 4 years ago by korli (previous) (diff)

comment:2 by korli, 4 years ago

Owner: changed from nobody to korli
Status: newassigned

comment:3 by korli, 4 years ago

Milestone: UnscheduledR1/beta3

comment:5 by korli, 4 years ago

Resolution: fixed
Status: assignedclosed

Applied in hrev54701

Note: See TracTickets for help on using tickets.