import.c

Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 static int cmd_import(int argc,char **argv)
00003 {
00004  void *handle;
00005  void (*initcmd)(void *);
00006  char *error;
00007 
00008  handle = dlopen(argv[1], RTLD_NOW|RTLD_GLOBAL);
00009  if (!handle) {
00010          fprintf(stderr, "%s\n", dlerror());
00011          exit(EXIT_FAILURE);
00012  }
00013 
00014  dlerror();    /* Clear any existing error */
00015 
00016  /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
00017         would seem more natural, but the C99 standard leaves
00018         casting from "void *" to a function pointer undefined.
00019         The assignment used below is the POSIX.1-2003 (Technical
00020         Corrigendum 1) workaround; see the Rationale for the
00021         POSIX specification of dlsym(). */
00022 
00023  initcmd = dlsym(handle, "initcmd");
00024 
00025  if ((error = dlerror()) != NULL)  {
00026          fprintf(stderr, "%s\n", error);
00027          exit(EXIT_FAILURE);
00028  }
00029 
00030  initcmd(mysymbol_head);
00031 
00032 // dlclose(handle);
00033  return 0;
00034 }
00035 
00036 mycmd_init(import,cmd_import,"cmds","echo");

Generated on Fri Nov 5 07:24:46 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6