summaryrefslogtreecommitdiff
path: root/Src/compat.c
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2000-09-16 18:57:45 +0000
committerClint Adams <clint@users.sourceforge.net>2000-09-16 18:57:45 +0000
commit2742cb14ce02354f6c9a2a2a61f793f9a1932924 (patch)
tree7c098832770e48dcc5d4c2cb27c32ed464fb3720 /Src/compat.c
parent73e23c7999196642fcf3448013b4e37b03044e8c (diff)
downloadzsh-2742cb14ce02354f6c9a2a2a61f793f9a1932924.tar.gz
zsh-2742cb14ce02354f6c9a2a2a61f793f9a1932924.zip
12814: zasprintf
Diffstat (limited to 'Src/compat.c')
-rw-r--r--Src/compat.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/Src/compat.c b/Src/compat.c
index 8cfb8a3a5..0c7009b5f 100644
--- a/Src/compat.c
+++ b/Src/compat.c
@@ -407,6 +407,80 @@ zchdir(char *dir)
#endif
}
+#ifndef HAVE_ASPRINTF
+/**/
+# ifndef USE_VARARGS
+/**/
+mod_export int
+zasprintf(char **strp, const char *format, int arg1, int arg2)
+{
+ char *buf;
+
+ buf = (char *)zalloc(PATH_MAX);
+
+ snprintf(buf, PATH_MAX, format, arg1, arg2);
+ *strp = buf;
+ return strlen(buf);
+}
+
+/**/
+# else
+
+/**/
+# ifdef PREFER_STDARG
+
+/**/
+mod_export int
+zasprintf(char **strp, const char *format, ...)
+{
+
+/**/
+# else
+
+/**/
+# if __GNUC__ > 1
+/* Doing this the "right way" will effect a broken compat.epro file. *
+ * This kludge should work with gcc2 until a better solution is available */
+
+/**/
+mod_export int
+zasprintf(char **strp, const char *format, __builtin_va_alist_t __builtin_va_alist, __va_ellipsis)
+{
+
+/**/
+# else
+# error varargs prototyping kludge failed
+/**/
+# endif
+
+/**/
+# endif
+ va_list arg;
+
+ char *buf;
+
+ buf = (char *)zalloc(PATH_MAX);
+
+# ifdef PREFER_STDARG
+ va_start(arg, format);
+# else
+ va_start(arg);
+# endif
+
+#ifdef HAVE_VSNPRINTF
+ vsnprintf(buf, PATH_MAX, format, arg);
+#else
+#error You have varargs but no vsnprintf
+#endif
+ va_end (arg);
+
+ *strp = buf;
+ return strlen(buf);
+}
+/**/
+# endif
+#endif
+
/*
* How to print out a 64 bit integer. This isn't needed (1) if longs
* are 64 bit, since ordinary %ld will work (2) if we couldn't find a