Blame m4/va_copy.m4

Packit Service a2489d
# Directly out of glib.  We don't do copy-by-value and other really
Packit Service a2489d
# pessimistic tests, since just about all systems will have one of these.
Packit Service a2489d
# Add them if needed.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([lftp_VA_COPY],
Packit Service a2489d
[
Packit Service a2489d
   AC_CACHE_CHECK([for an implementation of va_copy()],lftp_cv_va_copy,[
Packit Service a2489d
      AC_RUN_IFELSE([AC_LANG_SOURCE([[
Packit Service a2489d
      #include <stdarg.h>
Packit Service a2489d
      #include <stdlib.h>
Packit Service a2489d
      void f (int i, ...) {
Packit Service a2489d
	 va_list args1, args2;
Packit Service a2489d
	 va_start (args1, i);
Packit Service a2489d
	 va_copy (args2, args1);
Packit Service a2489d
	 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
Packit Service a2489d
	    exit (1);
Packit Service a2489d
	 va_end (args1); va_end (args2);
Packit Service a2489d
      }
Packit Service a2489d
      int main() {
Packit Service a2489d
	 f (0, 42);
Packit Service a2489d
	 return 0;
Packit Service a2489d
      }]])],[lftp_cv_va_copy=yes],[lftp_cv_va_copy=no],[lftp_cv_va_copy=yes])
Packit Service a2489d
   ])
Packit Service a2489d
   if test x$lftp_cv_va_copy != xyes; then
Packit Service a2489d
      AC_CACHE_CHECK([for an implementation of __va_copy()],lftp_cv___va_copy,[
Packit Service a2489d
	 AC_RUN_IFELSE([AC_LANG_SOURCE([[
Packit Service a2489d
	 #include <stdarg.h>
Packit Service a2489d
         #include <stdlib.h>
Packit Service a2489d
	 void f (int i, ...) {
Packit Service a2489d
	    va_list args1, args2;
Packit Service a2489d
	    va_start (args1, i);
Packit Service a2489d
	    __va_copy (args2, args1);
Packit Service a2489d
	    if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
Packit Service a2489d
	       exit (1);
Packit Service a2489d
	    va_end (args1); va_end (args2);
Packit Service a2489d
	 }
Packit Service a2489d
	 int main() {
Packit Service a2489d
	    f (0, 42);
Packit Service a2489d
	    return 0;
Packit Service a2489d
	 }]])],[lftp_cv___va_copy=yes],[lftp_cv___va_copy=no],[lftp_cv___va_copy=no])
Packit Service a2489d
      ])
Packit Service a2489d
   fi
Packit Service a2489d
Packit Service a2489d
   if test "x$lftp_cv_va_copy" = "xyes"; then
Packit Service a2489d
	   va_copy_func=va_copy
Packit Service a2489d
   elif test "x$lftp_cv___va_copy" = "xyes"; then
Packit Service a2489d
	   va_copy_func=__va_copy
Packit Service a2489d
   fi
Packit Service a2489d
Packit Service a2489d
   if test -n "$va_copy_func"; then
Packit Service a2489d
       AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,[A 'va_copy' style function])
Packit Service a2489d
Packit Service a2489d
   else
Packit Service a2489d
Packit Service a2489d
      AC_CACHE_CHECK([whether va_lists can be copied by value],lftp_cv_va_val_copy,[
Packit Service a2489d
	   AC_RUN_IFELSE([AC_LANG_SOURCE([[
Packit Service a2489d
	   #include <stdarg.h>
Packit Service a2489d
	   #include <string.h>
Packit Service a2489d
           #include <stdlib.h>
Packit Service a2489d
	   void f (int i, ...) {
Packit Service a2489d
	   va_list args1, args2;
Packit Service a2489d
	   va_start (args1, i);
Packit Service a2489d
Packit Service a2489d
	   memmove(&args2, &args1, sizeof(args1));
Packit Service a2489d
	   if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
Packit Service a2489d
	     exit (1);
Packit Service a2489d
	   va_end (args1); va_end (args2);
Packit Service a2489d
	   }
Packit Service a2489d
	   int main() {
Packit Service a2489d
	     f (0, 42);
Packit Service a2489d
	     return 0;
Packit Service a2489d
	   }]])],[lftp_cv_va_val_copy=yes],[lftp_cv_va_val_copy=no],[lftp_cv_va_val_copy=no])
Packit Service a2489d
      ])
Packit Service a2489d
Packit Service a2489d
      if test x$lftp_cv_va_val_copy = xyes; then
Packit Service a2489d
	 AC_DEFINE(VA_VAL_COPY,1,[Define to 1 if va_lists can be copied by value])
Packit Service a2489d
      else
Packit Service a2489d
	 AC_CACHE_CHECK([whether va_lists can be copied by pointer],lftp_cv_va_ptr_copy,[
Packit Service a2489d
	      AC_RUN_IFELSE([AC_LANG_SOURCE([[
Packit Service a2489d
	      #include <stdarg.h>
Packit Service a2489d
              #include <stdlib.h>
Packit Service a2489d
	      void f (int i, ...) {
Packit Service a2489d
	      va_list args1, args2;
Packit Service a2489d
	      va_start (args1, i);
Packit Service a2489d
Packit Service a2489d
	      *args2 = *args1;
Packit Service a2489d
	      if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
Packit Service a2489d
		exit (1);
Packit Service a2489d
	      va_end (args1); va_end (args2);
Packit Service a2489d
	      }
Packit Service a2489d
	      int main() {
Packit Service a2489d
		f (0, 42);
Packit Service a2489d
		return 0;
Packit Service a2489d
	      }]])],[lftp_cv_va_ptr_copy=yes],[lftp_cv_va_ptr_copy=no],[lftp_cv_va_ptr_copy=no])
Packit Service a2489d
	 ])
Packit Service a2489d
Packit Service a2489d
	 if test x$lftp_cv_va_ptr_copy = xyes; then
Packit Service a2489d
	    AC_DEFINE(VA_PTR_COPY,1,[Define to 1 if va_lists can be copied by pointer])
Packit Service a2489d
	 fi
Packit Service a2489d
      fi
Packit Service a2489d
   fi
Packit Service a2489d
Packit Service a2489d
   if test x$lftp_cv_va_val_copy != xyes -a x$lftp_cv_va_ptr_copy != xyes -a \
Packit Service a2489d
           x$lftp_cv_va_copy != xyes -a x$lftp_cv___va_copy != xyes; then
Packit Service a2489d
	   AC_MSG_ERROR(Can't find a way to va_copy.)
Packit Service a2489d
   fi
Packit Service a2489d
Packit Service a2489d
   dnl ZZZ for autoheader sorting.
Packit Service a2489d
   AH_VERBATIM([_VA_ZZZ_COPY],
Packit Service a2489d
[#if !defined (VA_COPY)
Packit Service a2489d
#  if defined (VA_PTR_COPY)
Packit Service a2489d
#    define VA_COPY(ap1, ap2)   (*(ap1) = *(ap2))
Packit Service a2489d
#  elif defined (VA_VAL_COPY)
Packit Service a2489d
#    include <string.h>
Packit Service a2489d
#    define VA_COPY(to,from) (memcpy(&(to),&(from),sizeof((to))))
Packit Service a2489d
#  endif
Packit Service a2489d
#endif /* !VA_COPY */])
Packit Service a2489d
])