You've already forked opencryptoki
mirror of
https://github.com/opencryptoki/opencryptoki.git
synced 2026-10-28 18:37:25 +03:00
To avoid nasty preprocessor defines everywhere, encapsulate everything into a new header `platform.h`, that handles everything automatically. Doing this also avoids situations where the preprocessor goes into a recursive header lookup, trying to look for a header first under usr/include and finding the same file that triggered the search in the first place. All AIX-specific headers now live under their own folder at usr/lib/common/aix and are automatically included when platform.h demands it. None of these headers are not meant to be included directly - use platform.h instead. Signed-off-by: Akash Kulhalli <akash.kulhalli@ibm.com>
62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
/*
|
|
* COPYRIGHT (c) International Business Machines Corp. 2024
|
|
*
|
|
* This program is provided under the terms of the Common Public License,
|
|
* version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
|
|
* software constitutes recipient's acceptance of CPL-1.0 terms which can be
|
|
* found in the file LICENSE file or at
|
|
* https://opensource.org/licenses/cpl1.0.php
|
|
*/
|
|
#ifndef UTIL_LINUX_ASPRINTF_H
|
|
#define UTIL_LINUX_ASPRINTF_H
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
|
|
#ifndef HAVE_VASPRINTF
|
|
static inline
|
|
int vasprintf(char **strp, const char *fmt, va_list ap)
|
|
{
|
|
int str_size = -1, len;
|
|
va_list cap;
|
|
|
|
va_copy(cap, ap);
|
|
|
|
len = vsnprintf(0, 0, fmt, cap);
|
|
va_end(cap);
|
|
|
|
if (len < 0)
|
|
return -1;
|
|
|
|
*strp = (char *)malloc (len + 1);
|
|
|
|
if (!*strp)
|
|
return -1;
|
|
|
|
str_size = vsnprintf(*strp, len + 1, fmt, ap);
|
|
if (str_size < 0 || str_size >= len + 1) {
|
|
free(*strp);
|
|
str_size = -1;
|
|
}
|
|
return str_size;
|
|
}
|
|
#endif
|
|
|
|
#ifndef HAVE_ASPRINTF
|
|
static inline
|
|
int asprintf(char **strp, const char *fmt, ...)
|
|
{
|
|
int res;
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
res = vasprintf (strp, fmt, ap);
|
|
va_end (ap);
|
|
|
|
return res;
|
|
}
|
|
#endif
|
|
|
|
#endif
|