Retry only for https protocol
[elinks.git] / src / util / snprintf.h
blob1f3435a661ba812422e7189e070a9336b560b0e2
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 */
10 #include <stdarg.h>
12 /* XXX: This is not quite the best place for it, perhaps. But do we have
13 * a better one now? --pasky */
14 #ifndef VA_COPY
15 #ifdef HAVE_VA_COPY
16 #define VA_COPY(dest, src) __va_copy(dest, src)
17 #else
18 #define VA_COPY(dest, src) (dest) = (src)
19 #endif
20 #endif
22 #ifdef CONFIG_OWN_LIBC
23 #undef HAVE_VSNPRINTF
24 #undef HAVE_C99_VSNPRINTF
25 #undef HAVE_SNPRINTF
26 #undef HAVE_C99_SNPRINTF
27 #undef HAVE_VASPRINTF
28 #undef HAVE_ASPRINTF
29 #else
30 #include <stdio.h> /* The system's snprintf(). */
31 #endif
34 #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
35 #undef vsnprintf
36 #define vsnprintf elinks_vsnprintf
37 int elinks_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
38 #endif
40 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
41 #undef snprintf
42 #define snprintf elinks_snprintf
43 int elinks_snprintf(char *str, size_t count, const char *fmt, ...);
44 #endif
47 #ifndef HAVE_VASPRINTF
48 #undef vasprintf
49 #define vasprintf elinks_vasprintf
50 int elinks_vasprintf(char **ptr, const char *fmt, va_list ap);
51 #endif
53 #ifndef HAVE_ASPRINTF
54 #undef asprintf
55 #define asprintf elinks_asprintf
56 int elinks_asprintf(char **ptr, const char *fmt, ...);
57 #endif
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. */
64 #ifndef _GNU_SOURCE
65 #define _GNU_SOURCE /* We want vasprintf() */
66 #endif
68 #include <stdlib.h>
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) {
75 char *str1;
76 unsigned char *str2;
77 int size;
79 if (vasprintf(&str1, fmt, ap) < 0)
80 return NULL;
82 size = strlen(str1) + 1;
83 str2 = mem_alloc(size);
84 if (str2) memcpy(str2, str1, size);
85 free(str1);
87 return str2;
90 unsigned char *asprintfa(const char *fmt, ...);
93 #endif