os: drop Xasprintf() and Xvasprintf()

The supported platforms already have asprintf() and vasprintf(),
so there's no need for having our own implementation anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-03-04 18:48:01 +01:00
parent f6d63f96cd
commit b443f4bb88
3 changed files with 1 additions and 85 deletions

View File

@ -22,6 +22,7 @@
#include <dix-config.h> #include <dix-config.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include "os/bug_priv.h" #include "os/bug_priv.h"

View File

@ -49,23 +49,12 @@
* on failure. * on failure.
*/ */
extern _X_EXPORT int extern _X_EXPORT int
Xasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, ...)
_X_ATTRIBUTE_PRINTF(2, 3);
extern _X_EXPORT int
Xvasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, va_list va)
_X_ATTRIBUTE_PRINTF(2, 0);
extern _X_EXPORT int
XNFasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, ...) XNFasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, ...)
_X_ATTRIBUTE_PRINTF(2, 3); _X_ATTRIBUTE_PRINTF(2, 3);
extern _X_EXPORT int extern _X_EXPORT int
XNFvasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, va_list va) XNFvasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, va_list va)
_X_ATTRIBUTE_PRINTF(2, 0); _X_ATTRIBUTE_PRINTF(2, 0);
#if !defined(HAVE_ASPRINTF) && !defined(HAVE_VASPRINTF)
#define asprintf Xasprintf
#define vasprintf Xvasprintf
#endif
/* /*
* These functions provide a portable implementation of the linux kernel * These functions provide a portable implementation of the linux kernel
* scnprintf & vscnprintf routines that return the number of bytes actually * scnprintf & vscnprintf routines that return the number of bytes actually

View File

@ -65,80 +65,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#ifdef asprintf
#undef asprintf
#endif
#ifdef vasprintf
#undef vasprintf
#endif
#ifndef va_copy
#ifdef __va_copy
#define va_copy __va_copy
#else
#error "no working va_copy was found"
#endif
#endif
/**
* Varargs sprintf that allocates a string buffer the right size for
* the pattern & data provided and prints the requested data to it.
*
* @param ret Pointer to which the newly allocated buffer is written
* (contents undefined on error)
* @param format printf style format string
* @param va variable argument list
* @return size of allocated buffer, or -1 on error.
*/
int
Xvasprintf(char **ret, const char *_X_RESTRICT_KYWD format, va_list va)
{
#ifdef HAVE_VASPRINTF
return vasprintf(ret, format, va);
#else
int size;
va_list va2;
va_copy(va2, va);
size = vsnprintf(NULL, 0, format, va2);
va_end(va2);
*ret = calloc(1, size + 1);
if (*ret == NULL)
return -1;
vsnprintf(*ret, size + 1, format, va);
(*ret)[size] = 0;
return size;
#endif
}
#ifndef HAVE_VASPRINTF
#define vasprintf Xvasprintf
#endif
/**
* sprintf that allocates a string buffer the right size for
* the pattern & data provided and prints the requested data to it.
*
* @param ret Pointer to which the newly allocated buffer is written
* (contents undefined on error)
* @param format printf style format string
* @param ... arguments for specified format
* @return size of allocated buffer, or -1 on error.
*/
int
Xasprintf(char **ret, const char *_X_RESTRICT_KYWD format, ...)
{
int size;
va_list va;
va_start(va, format);
size = vasprintf(ret, format, va);
va_end(va);
return size;
}
/** /**
* Varargs sprintf that allocates a string buffer the right size for * Varargs sprintf that allocates a string buffer the right size for
* the pattern & data provided and prints the requested data to it. * the pattern & data provided and prints the requested data to it.