35 #include <sys/types.h> 
   51 #define WIN32_LEAN_AND_MEAN 
   55 lt_dlopen (
const char *x)
 
   58         return GetModuleHandle (
NULL);
 
   60     return LoadLibrary(x);
 
   64 lt_dlsym (HMODULE hmod, 
const char *p)
 
   71     modun.modaddr = GetProcAddress(hmod, p);
 
   76 #define lt_dlsym(x,y)   GetProcAddress(x, y) 
   79 #define lt_dlclose(x)   FreeLibrary(x) 
   82 #define lt_dlhandle HMODULE 
   85 static char errbuf[64];
 
   89     sprintf(errbuf, 
_(
"LoadLibrary/GetProcAddress error %d"), (
int)GetLastError());
 
   94 #elif   defined(USE_LIBDL) 
   98 #define lt_dlopen(x)    dlopen(x, RTLD_LAZY | RTLD_GLOBAL) 
   99 #define lt_dlsym(x,y)   dlsym(x, y) 
  100 #define lt_dlclose(x)   dlclose(x) 
  101 #define lt_dlerror()    dlerror() 
  104 #define lt_dlhandle void * 
  113 #define COB_LIB_EXPIMP 
  118 #define COB_MAX_COBCALL_PARMS   16 
  119 #define CALL_BUFF_SIZE      256U 
  120 #define CALL_BUFF_MAX       (CALL_BUFF_SIZE - 1U) 
  122 #define HASH_SIZE       131U 
  179 #undef  COB_SYSTEM_GEN 
  181 #define COB_SYSTEM_GEN(x,y,z)       { x, {(void *(*)())z} }, 
  183 #define COB_SYSTEM_GEN(x,y,z)       { x, {(void *(*)(void *))z} }, 
  190 #undef  COB_SYSTEM_GEN 
  192 static const unsigned char  hexval[] = 
"0123456789ABCDEF";
 
  194 #ifdef  HAVE_DESIGNATED_INITS 
  195 static const unsigned char  valid_char[256] = {
 
  261 static unsigned char        valid_char[256];
 
  263     "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
 
  273           "%s '%s'", msg, entry);
 
  298     for (p = (
char *)path; *p; p++, size++) {
 
  308     for (p = (
char *)path; *p; p++, pstr++) {
 
  310         if (*p == (
unsigned char)
'/') {
 
  311             *pstr = (
unsigned char)
'\\';
 
  315         if (*p == (
unsigned char)
'\\') {
 
  316             *pstr = (
unsigned char)
'/';
 
  323     resolve_path = 
cob_malloc (
sizeof (
char *) * i);
 
  332         if (stat (p, &st) || !(S_ISDIR (st.st_mode))) {
 
  341             if(strcmp(resolve_path[i], p) == 0) {
 
  348             resolve_path[resolve_size++] = p;
 
  358     int (*cancel_func)(
const int, 
void *, 
void *, 
void *, 
void *);
 
  399     for (; dynptr; dynptr = dynptr->
next) {
 
  406         *base_hash = p->
next;
 
  422     if (buffsize > call_lastsize) {
 
  423         call_lastsize = buffsize;
 
  435     for (dynptr = base_dynload_ptr; dynptr; dynptr = dynptr->
next) {
 
  436         if (!strcmp (path, dynptr->
path)) {
 
  447     base_dynload_ptr = dynptr;
 
  454     lt_dlhandle     libhandle;
 
  456 #if defined(_WIN32) || defined(__CYGWIN__) 
  462     for (preptr = base_preload_ptr; preptr; preptr = preptr->
next) {
 
  463         if (!strcmp (path, preptr->
path)) {
 
  466 #if defined(_WIN32) || defined(__CYGWIN__) 
  468         if (!preptr->
next) last_elem = preptr;
 
  472     if (access (path, 
R_OK) != 0) {
 
  476     libhandle = lt_dlopen (path);
 
  483     preptr->
handle = libhandle;
 
  485 #if defined(_WIN32) || defined(__CYGWIN__) 
  498         last_elem->
next = preptr;
 
  502         base_preload_ptr = preptr;
 
  506     base_preload_ptr = preptr;
 
  525     unsigned int    val = 0;
 
  537     const unsigned int nocanc)
 
  552         p->
path = _fullpath (
NULL, path, 1);
 
  553 #elif   defined(HAVE_CANONICALIZE_FILE_NAME) 
  555         p->
path = canonicalize_file_name (path);
 
  556 #elif   defined(HAVE_REALPATH) 
  560         if (realpath (path, s) != 
NULL) {
 
  574     val = 
hash ((
const unsigned char *)name);
 
  575     p->
next = call_table[val];
 
  588     p = call_table[
hash ((
const unsigned char *)name)];
 
  590     for (; p; p = p->
next) {
 
  591         if (strcmp (name, p->
name) == 0) {
 
  603     const unsigned char *s;
 
  621     p = (
unsigned char *)call_entry_buff;
 
  622     s = (
const unsigned char *)name;
 
  623     if (
unlikely(*s <= (
unsigned char)
'9' && *s >= (
unsigned char)
'0')) {
 
  624         *p++ = (
unsigned char)
'_';
 
  627         if (
likely(valid_char[*s])) {
 
  630             *p++ = (
unsigned char)
'_';
 
  631             if (*s == (
unsigned char)
'-') {
 
  632                 *p++ = (
unsigned char)
'_';
 
  634                 *p++ = hexval[*s / 16U];
 
  635                 *p++ = hexval[*s % 16U];
 
  662     if (mainhandle != 
NULL) {
 
  663         func = lt_dlsym (mainhandle, call_entry_buff);
 
  666             resolve_error = 
NULL;
 
  672     for (preptr = base_preload_ptr; preptr; preptr = preptr->
next) {
 
  673         func = lt_dlsym (preptr->
handle, call_entry_buff);
 
  676             resolve_error = 
NULL;
 
  682     for (preptr = base_dynload_ptr; preptr; preptr = preptr->
next) {
 
  686         func = lt_dlsym (preptr->
handle, call_entry_buff);
 
  690             resolve_error = 
NULL;
 
  696 #if defined(USE_LIBDL) && defined (RTLD_DEFAULT) 
  697     func = lt_dlsym (RTLD_DEFAULT, call_entry_buff);
 
  700         resolve_error = 
NULL;
 
  706     s = (
const unsigned char *)name;
 
  710         if (!call_entry2_buff) {
 
  714         for (; *s; ++s, ++p) {
 
  717             } 
else if (cobsetptr->
name_convert == 2 && islower (*s)) {
 
  724         s = (
const unsigned char *)call_entry2_buff;
 
  729     strcpy (call_filename_buff, s);
 
  730     for(p = call_filename_buff; *p; ++p) {
 
  733     handle = lt_dlopen (call_filename_buff);
 
  734     if (handle != 
NULL) {
 
  737         func = lt_dlsym (handle, call_entry_buff);
 
  739             insert (name, func, handle, 
NULL, call_filename_buff, 0);
 
  740             resolve_error = 
NULL;
 
  749         if (access (call_filename_buff, 
R_OK) != 0) {
 
  753         handle = lt_dlopen (call_filename_buff);
 
  754         if (handle != 
NULL) {
 
  757             func = lt_dlsym (handle, call_entry_buff);
 
  760                     call_filename_buff, 0);
 
  761                 resolve_error = 
NULL;
 
  771         if (resolve_path[i] == 
NULL) {
 
  776                   "%s%c%s.%s", resolve_path[i],
 
  782         if (access (call_filename_buff, 
R_OK) == 0) {
 
  783             handle = lt_dlopen (call_filename_buff);
 
  784             if (handle != 
NULL) {
 
  787                 func = lt_dlsym (handle, call_entry_buff);
 
  790                         call_filename_buff, 0);
 
  791                     resolve_error = 
NULL;
 
  813     for (p = name; *p; p++) {
 
  814         if (*p == 
'/' || *p == 
'\\') {
 
  835     for (p = (
char *)name, size1 = 0; *p; p++, size1++) {
 
  836         if (*p == 
'/' || *p == 
'\\') {
 
  868     if (!resolve_error) {
 
  869         p = 
_(
"Indeterminable error in resolve of COBOL CALL");
 
  872         resolve_error = 
NULL;
 
  894     for (; p; p = p->
next) {
 
  958         const unsigned int errind, 
const int fold_case)
 
  977     for (psyst = system_tab; psyst->
syst_name; ++psyst) {
 
 1033     q = &call_table[
hash ((
const unsigned char *)entry)];
 
 1037     for (; p; p = p->
next) {
 
 1038         if (strcmp (entry, p->
name) == 0) {
 
 1053     int (*cancel_func)(
const int, 
void *, 
void *, 
void *, 
void *);
 
 1058     if (!f || f->
size == 0) {
 
 1080 cob_call (
const char *name, 
const int argc, 
void **argv)
 
 1098     pargv = 
cob_malloc (COB_MAX_FIELD_PARAMS * 
sizeof(
void *));
 
 1101     for (i = 0; i < argc; ++i) {
 
 1104 #if COB_MAX_FIELD_PARAMS == 16 || \ 
 1105     COB_MAX_FIELD_PARAMS == 36 || \ 
 1106     COB_MAX_FIELD_PARAMS == 56 || \ 
 1107     COB_MAX_FIELD_PARAMS == 76 || \ 
 1108     COB_MAX_FIELD_PARAMS == 96 
 1110 #error  "Invalid COB_MAX_FIELD_PARAMS value" 
 1112     i =  unifunc.
funcint (pargv[0], pargv[1], pargv[2], pargv[3]
 
 1113                 ,pargv[4], pargv[5], pargv[6], pargv[7]
 
 1114                 ,pargv[8], pargv[9], pargv[10], pargv[11]
 
 1115                 ,pargv[12], pargv[13], pargv[14], pargv[15]
 
 1116 #
if COB_MAX_FIELD_PARAMS > 16
 
 1117                 ,pargv[16], pargv[17], pargv[18], pargv[19]
 
 1118                 ,pargv[20], pargv[21], pargv[22], pargv[23]
 
 1119                 ,pargv[24], pargv[25], pargv[26], pargv[27]
 
 1120                 ,pargv[28], pargv[29], pargv[30], pargv[31]
 
 1121                 ,pargv[32], pargv[33], pargv[34], pargv[35]
 
 1122 #
if COB_MAX_FIELD_PARAMS > 36
 
 1123                 ,pargv[36], pargv[37], pargv[38], pargv[39]
 
 1124                 ,pargv[40], pargv[41], pargv[42], pargv[43]
 
 1125                 ,pargv[44], pargv[45], pargv[46], pargv[47]
 
 1126                 ,pargv[48], pargv[49], pargv[50], pargv[51]
 
 1127                 ,pargv[52], pargv[53], pargv[54], pargv[55]
 
 1128 #
if COB_MAX_FIELD_PARAMS > 56
 
 1129                 ,pargv[56], pargv[57], pargv[58], pargv[59]
 
 1130                 ,pargv[60], pargv[61], pargv[62], pargv[63]
 
 1131                 ,pargv[64], pargv[65], pargv[66], pargv[67]
 
 1132                 ,pargv[68], pargv[69], pargv[70], pargv[71]
 
 1133                 ,pargv[72], pargv[73], pargv[74], pargv[75]
 
 1134 #
if COB_MAX_FIELD_PARAMS > 76
 
 1135                 ,pargv[76], pargv[77], pargv[78], pargv[79]
 
 1136                 ,pargv[80], pargv[81], pargv[82], pargv[83]
 
 1137                 ,pargv[84], pargv[85], pargv[86], pargv[87]
 
 1138                 ,pargv[88], pargv[89], pargv[90], pargv[91]
 
 1139                 ,pargv[92], pargv[93], pargv[94], pargv[95]
 
 1150 cob_func (
const char *name, 
const int argc, 
void **argv)
 
 1169     if (cob_jmp_primed) {
 
 1195     if (!cob_jmp_primed) {
 
 1211 #ifndef COB_ALT_HASH 
 1215     if (call_filename_buff) {
 
 1217         call_filename_buff = 
NULL;
 
 1219     if (call_entry_buff) {
 
 1221         call_entry_buff = 
NULL;
 
 1223     if (call_entry2_buff) {
 
 1225         call_entry2_buff = 
NULL;
 
 1231     if (resolve_error_buff) {
 
 1233         resolve_error_buff = 
NULL;
 
 1235     if (resolve_alloc) {
 
 1237         resolve_alloc = 
NULL;
 
 1241         resolve_path = 
NULL;
 
 1244 #ifndef COB_ALT_HASH 
 1262 #ifndef COB_ALT_HASH 
 1271     for (h = base_preload_ptr; h;) {
 
 1282     base_preload_ptr = 
NULL;
 
 1283     for (h = base_dynload_ptr; h;) {
 
 1294     base_dynload_ptr = 
NULL;
 
 1296 #if !defined(_WIN32) && !defined(USE_LIBDL) 
 1313 #ifndef HAVE_DESIGNATED_INITS 
 1314     const unsigned char     *pv;
 
 1323     base_preload_ptr = 
NULL;
 
 1324     base_dynload_ptr = 
NULL;
 
 1325     resolve_path = 
NULL;
 
 1326     resolve_alloc = 
NULL;
 
 1327     resolve_error = 
NULL;
 
 1328     resolve_error_buff = 
NULL;
 
 1331     call_filename_buff = 
NULL;
 
 1332     call_entry_buff = 
NULL;
 
 1333     call_entry2_buff = 
NULL;
 
 1339 #ifndef HAVE_DESIGNATED_INITS 
 1340     memset (valid_char, 0, 
sizeof(valid_char));
 
 1341     for (pv = pvalid_char; *pv; ++pv) {
 
 1342         valid_char[*pv] = 1;
 
 1349 #ifndef COB_ALT_HASH 
 1378 #ifndef COB_BORKED_DLOPEN 
 1379     mainhandle = lt_dlopen (
NULL);
 
 1388             for (t = s; *t; ++t) {
 
 1403             if (i == resolve_size) {
 
void cob_free(void *mptr)
static char * resolve_error
static void cob_set_library_path(const char *path)
struct struct_handle * next
static char * resolve_alloc
void cob_cancel_field(const cob_field *f, const struct cob_call_struct *cs)
static size_t resolve_size
static size_t cache_preload(const char *path)
static char ** resolve_path
static void * cob_get_buff(const size_t buffsize)
unsigned int module_active
static struct call_hash ** call_table
static void insert(const char *name, void *func, lt_dlhandle handle, cob_module *module, const char *path, const unsigned int nocanc)
static const struct system_table system_tab[]
static cob_module * module
static COB_INLINE unsigned int hash(const unsigned char *s)
static size_t call_lastsize
int cob_func(const char *name, const int argc, void **argv)
void * cob_savenv2(struct cobjmp_buf *jbuf, const int jsize)
void * cob_resolve_cobol(const char *name, const int fold_case, const int errind)
static const char * cob_chk_dirp(const char *name)
static void * lookup(const char *name)
void * cob_resolve(const char *name)
const char * cob_resolve_error(void)
static void cache_dynload(const char *path, lt_dlhandle handle)
cob_call_union module_entry
const char * cob_cstr_name
static char * resolve_error_buff
void cob_cancel(const char *name)
static cob_settings * cobsetptr
void cob_longjmp(struct cobjmp_buf *jbuf)
void cob_field_to_string(const cob_field *, void *, const size_t)
static void do_cancel_module(struct call_hash *p, struct call_hash **base_hash, struct call_hash *prev)
unsigned int * module_ref_count
void cob_fatal_error(const int fatal_error)
void cob_runtime_error(const char *,...) COB_A_FORMAT12
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
void * cob_resolve_func(const char *name)
unsigned int no_phys_cancel
static const unsigned char pvalid_char[]
static void * call_buffer
void cob_set_exception(const int id)
void * cob_savenv(struct cobjmp_buf *jbuf)
static cob_global * cobglobptr
void cob_set_cancel(cob_module *m)
static const unsigned char hexval[]
#define COB_FERROR_INITIALIZED
void cob_call_error(void)
static char * call_filename_buff
int cob_call(const char *name, const int argc, void **argv)
static void set_resolve_error(const char *msg, const char *entry)
static unsigned char valid_char[256]
static char * cob_chk_call_path(const char *name, char **dirent)
char * cob_strdup(const char *)
char * cob_strcat(char *str1, char *str2)
static char * call_entry_buff
static unsigned int cob_jmp_primed
void * cob_malloc(const size_t size)
void * cob_call_field(const cob_field *f, const struct cob_call_struct *cs, const unsigned int errind, const int fold_case)
static unsigned char * call_entry2_buff
static struct struct_handle * base_dynload_ptr
cob_call_union cob_cstr_cancel
static void * cob_resolve_internal(const char *name, const char *dirent, const int fold_case)
const char ** module_path
cob_call_union module_cancel
void * cob_fast_malloc(const size_t size)
#define COB_MAX_FIELD_PARAMS
unsigned int name_convert
void cob_init_call(cob_global *lptr, cob_settings *sptr)
static lt_dlhandle mainhandle
unsigned char flag_no_phys_canc
unsigned int cob_physical_cancel
static struct struct_handle * base_preload_ptr
cob_call_union cob_cstr_call
void cob_stop_run(const int status)