Listing 2

// Ch function file for ORJ_ReadDatabaseA()

#include <dlfcn.h>
#include <stdlib.h>
#include <openrj/openrj.h>

ORJ_CALL(ORJRC) ORJ_ReadDatabaseA(char const          *jarName
                                , IORJAllocator       *ator
                                , unsigned            flags
                                , ORJDatabaseA const  **pdatabase
                                , ORJError            *error)
{
  void  *hinst  = dlopen("libopenrjch.dl", RTLD_LAZY);
  ORJRC retVal;
  if(NULL == hinst)
  {
    fprintf(stderr, "Error: dlopen(): %s\n", dlerror());
    fprintf(stderr, "Cannot load server for Open-RJ!\n");
    exit(EXIT_FAILURE);
  }
  else
  {
    void  *pfn = dlsym(hinst, "ORJ_ReadDatabaseA_chdl");
    if(NULL == pfn)
    {
      fprintf(stderr, "Error: %s(): dlsym()L %s\n"
            , __func__, dlerror());
      dlclose(hinst);
      exit(EXIT_FAILURE);
    }
    dlrunfun( pfn, &retVal, ORJ_ReadDatabaseA, jarName
            , ator, flags, pdatabase, error);
    dlclose(hinst);
  }
  return retVal;
}