/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include <stdio.h>

void func(int n, ...);
void vfunc(int n, va_list ap);

int main() {
    char    c1 = 'c';
    int     i1 = 10;
    double  d1 = 65536;

    func(0, c1, i1, d1);
    return 0;
}

void func(int n, ...) {
    va_list ap;

    va_start(ap, n); /* create a Ch va_list */
    vfunc(n, ap);
    va_end(ap);
}

void vfunc(int n, va_list ap) {
    void *fptr, *handle;

    handle = dlopen("libch.dl", RTLD_LAZY);
    if(handle == NULL) {
      printf("Error: dlopen(): %s\n", __func__, dlerror());
     return;
    }

    fptr = dlsym(handle, "vfunc_chdl");
    if(fptr == NULL)  {
       printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
       return;
    }
    dlrunfun(fptr, NULL, NULL, n, ap);

    if(dlclose(handle)!=0) {
       printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
       return;
    }
}
