/* program to test the dynamic loading of gamei386.so
   change paths/filenames as necessary */

#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <errno.h>
#if defined (__linux__)
  #include <mntent.h>
#endif
#include <dlfcn.h>

void *game_library;

int main (void) {
  void *(*GetGameAPI) (void *);
  void *dl_open;
/* char *path = "/data/games/quake2";
  char name[1024];
  char *name = "/usr/lib/libc.so";
*/
  char *name = "/home/maxwell/quake2-r0.0.8/debugi386/gamei386.so";
  const char *gamename = "gamei386.so";
  const char *dl_error;

  setreuid(getuid(), getuid());
  setegid(getgid());
  game_library = dlopen(name, RTLD_NOW);
  if (!game_library)
    printf("bad game_library\n");

  /* This works if you use /usr/lib/libc.so.4
  GetGameAPI = (void *)dlsym(game_library, "rand"); */

  /* This doesn't on gamei386.so */
  GetGameAPI = (void *)dlsym(game_library, "GetGameAPI");

  dl_error = dlerror();
  printf("dlerror: %s\nname: %s\n", dl_error, name); 

  return 0;
}
