about summary refs log tree commit diff
path: root/Src/system.h
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-06-05 16:55:38 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-06-05 16:55:38 +0000
commit11836eb5e32085f9808d35ca6e7dc23d61a5090b (patch)
tree52168c0739ffb9f0f00f92d5a8b9ccf5890ecee3 /Src/system.h
parent8346a5e8d28899f88c92ea3cd772012ad4a50e49 (diff)
downloadzsh-11836eb5e32085f9808d35ca6e7dc23d61a5090b.tar.gz
zsh-11836eb5e32085f9808d35ca6e7dc23d61a5090b.tar.xz
zsh-11836eb5e32085f9808d35ca6e7dc23d61a5090b.zip
22484: support varargs.h in addition to stdarg.h
Diffstat (limited to 'Src/system.h')
-rw-r--r--Src/system.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/Src/system.h b/Src/system.h
index 340f4693b..2f3dcd32a 100644
--- a/Src/system.h
+++ b/Src/system.h
@@ -153,8 +153,48 @@ char *alloca _((size_t));
 # include <stdlib.h>
 #endif
 
+/*
+ * Stuff with variable arguments.  We use definitions to make the
+ * same code work with varargs (the original K&R-style, just to
+ * be maximally compatible) and stdarg (which all modern systems
+ * should have).
+ *
+ * Ideally this should somehow be merged with the tricks performed
+ * with "_" in makepro.awk, but I don't understand makepro.awk.
+ * Currently we simply rely on the fact that makepro.awk has been
+ * hacked to leave alone argument lists that already contains VA_ALIST
+ * except for removing the VA_DCL and turning VA_ALIST into VA_ALIST_PROTO.
+ */
 #ifdef HAVE_STDARG_H
 # include <stdarg.h>
+# define VA_ALIST1(x)		x, ...
+# define VA_ALIST2(x,y)		x, y, ...
+# define VA_ALIST_PROTO1(x)	VA_ALIST1(x)
+# define VA_ALIST_PROTO2(x,y)	VA_ALIST2(x,y)
+# define VA_DCL
+# define VA_DEF_ARG(x)
+# define VA_START(ap,x)		va_start(ap, x)
+# define VA_GET_ARG(ap,x,t)
+#else
+# if HAVE_VARARGS_H
+#  include <varargs.h>
+#  define VA_ALIST1(x)		va_alist
+#  define VA_ALIST2(x,y)	va_alist
+/*
+ * In prototypes, assume K&R form and remove the variable list.
+ * This is about the best we can do without second-guessing the way
+ * varargs works on this system.  The _ trick should be able to
+ * do this for us but we've turned it off here.
+ */
+#  define VA_ALIST_PROTO1(x)
+#  define VA_ALIST_PROTO2(x,y)
+#  define VA_DCL		va_dcl
+#  define VA_DEF_ARG(x)		x
+#  define VA_START(ap,x)	va_start(ap);
+#  define VA_GET_ARG(ap,x,t)	(x = va_arg(ap, t))
+# else
+#  error "Your system has neither stdarg.h or varargs.h."
+# endif
 #endif
 
 #ifdef HAVE_ERRNO_H