1 #ifndef EL__UTIL_SNPRINTF_H
2 #define EL__UTIL_SNPRINTF_H
5 /* Do not use a 'format' token here as it gets defined at some dirty stinking
6 * places of ELinks, causing bug 244 (read as "compilation failures"). 'fmt'
7 * should do fine. --pasky */
12 /* XXX: This is not quite the best place for it, perhaps. But do we have
13 * a better one now? --pasky */
16 #define VA_COPY(dest, src) __va_copy(dest, src)
18 #define VA_COPY(dest, src) (dest) = (src)
22 #ifdef CONFIG_OWN_LIBC
24 #undef HAVE_C99_VSNPRINTF
26 #undef HAVE_C99_SNPRINTF
30 #include <stdio.h> /* The system's snprintf(). */
34 #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
36 #define vsnprintf elinks_vsnprintf
37 int elinks_vsnprintf(char *str
, size_t count
, const char *fmt
, va_list args
);
40 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
42 #define snprintf elinks_snprintf
43 int elinks_snprintf(char *str
, size_t count
, const char *fmt
, ...);
47 #ifndef HAVE_VASPRINTF
49 #define vasprintf elinks_vasprintf
50 int elinks_vasprintf(char **ptr
, const char *fmt
, va_list ap
);
55 #define asprintf elinks_asprintf
56 int elinks_asprintf(char **ptr
, const char *fmt
, ...);
60 /* These are wrappers for (v)asprintf() which return the strings allocated by
61 * ELinks' own memory allocation routines, thus it is usable in the context of
62 * standard ELinks memory managment. Just use these if you mem_free() the
63 * string later and use the original ones if you free() the string later. */
65 #define _GNU_SOURCE /* We want vasprintf() */
69 #include "util/string.h"
71 int vasprintf(char **ptr
, const char *fmt
, va_list ap
);
73 static inline unsigned char *
74 vasprintfa(const char *fmt
, va_list ap
) {
79 if (vasprintf(&str1
, fmt
, ap
) < 0)
82 size
= strlen(str1
) + 1;
83 str2
= mem_alloc(size
);
84 if (str2
) memcpy(str2
, str1
, size
);
90 unsigned char *asprintfa(const char *fmt
, ...);