/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/************************************************************
* File name: libgen.h
: Note: CH libgen.h header file wraper
************************************************************/
#ifndef _LIBGEN_H_
#define	_LIBGEN_H_

extern char *regcmp(const char *string1, /* char *string2  */  ... /*(char*)0*/);
extern char *regex(const char *re, const  char  *subject,  /* char *ret0 */ ...);

char **__loc1_ptr; 
#define __loc1 (*__loc1_ptr)


#if defined(_CHDLL_)
#include <dlfcn.h>
void *_ChLibgen_handle = dlopen("liblibgen.dl", RTLD_LAZY);
if(_ChLibgen_handle == NULL) {
   fprintf(_stderr, "Error: dlopen(): %s\n", dlerror());
   fprintf(_stderr, "       cannot get _ChLibgen_handle in libgen.h\n");
   exit(-1);
} 
else {
    void *fptr;
    __declspec(local) void ChLibgen_hInitialize(char ***loc1);

    fptr = dlsym(_ChLibgen_handle , "ChLibgen_hInitialize");
    if(fptr == NULL) { 
       fprintf(_stderr, "Error: dlsym(): %s\n", dlerror());
       exit(1);
    }
    dlrunfun(fptr, NULL, ChLibgen_hInitialize, &__loc1_ptr);
}
void _dlclose_libgen(void) {
   dlclose(_ChLibgen_handle);
}
atexit(_dlclose_libgen);
#endif

#endif /* _LIBGEN_H_ */
