#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>

#define PATH_LENGTH 256
      
int main(int argc, char * argv[])
{
	char path[PATH_LENGTH], * msg = NULL;
	int (*my_entry)();
	void * module;
      
	/* build the pathname for the module */
	getcwd(path, PATH_LENGTH);
	strcat(path, "/");
	strcat(path, argv[1]);
      
	/* load the module, and resolve symbols now */
	module = dlopen(path, RTLD_NOW);
	if(!module) {
		msg = dlerror();
		if(msg != NULL) {
			dlclose(module);
			exit(1);
		}
	}
      
	/* retrieve address of entry point */
	my_entry = dlsym(module, "entry");
	msg = dlerror();
	if(msg != NULL) {
		perror(msg);
		dlclose(module);
		exit(1);
	}
      
	/* call module entry point */
	my_entry();
      
	/* close module */
	if(dlclose(module)) {
		perror("error");
		exit(1);
	}
      
	return 0;
}                
