Skip to content
Snippets Groups Projects
Commit 85680977 authored by Cristian Galperti's avatar Cristian Galperti
Browse files

getalgoinfo with generic filename input

- to be refactored
parent 527beb8d
No related branches found
No related tags found
No related merge requests found
all: getalgoinfo.c
gcc getalgoinfo.c -o getalgoinfo -ldl
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <libgen.h>
#define ALGOINFOMAXLEN 1024 #define ALGOINFOMAXLEN 1024
...@@ -18,29 +19,45 @@ struct algoinfo { ...@@ -18,29 +19,45 @@ struct algoinfo {
int main(int argn, char *argv[]) int main(int argn, char *argv[])
{ {
char sofilename[1024];
char *filename;
char localfilename[1024];
char algoinfofcnname[1024];
void *libhnd; void *libhnd;
void (*algoinfofunc)(struct algoinfo *); void (*algoinfofunc)(struct algoinfo *);
struct algoinfo ai;
struct algoinfo ai; if(argn!=2)
{
libhnd=dlopen("./SCD_rtccode_02_02.so", RTLD_LAZY | RTLD_GLOBAL); printf("usage %s <scd .so filename>\n", argv[0]);
exit(-1);
}
//snprintf(sofilename, strlen(basename(argv[1]))+3,"./%s", argv[1]);
libhnd=dlopen(argv[1], RTLD_LAZY | RTLD_GLOBAL);
if(libhnd==NULL) if(libhnd==NULL)
{ {
printf("Error loading .so\n"); fprintf(stderr,"Error loading %s, try ldd .so to check libs\n", argv[1]);
exit(0); exit(0);
} }
algoinfofunc=dlsym(libhnd, "SCD_rtccode_02_02_GetAlgoInfo"); filename=basename(argv[1]);
snprintf(localfilename, strlen(filename)-2,"%s", filename);
snprintf(algoinfofcnname, strlen(localfilename)+13,"%s_GetAlgoInfo", localfilename);
algoinfofunc=dlsym(libhnd, algoinfofcnname);
if(algoinfofunc==NULL) if(algoinfofunc==NULL)
{ {
printf("Error loading SCD_rtccode_02_02_GetAlgoInfo\n"); fprintf(stderr,"Error finding %s in .so\n", algoinfofcnname);
perror(NULL); perror(NULL);
exit(0); exit(0);
} }
(*algoinfofunc)(&ai); (*algoinfofunc)(&ai);
printf("%d, %s\n", ai.len, ai.text); printf("%s (%d characters)\n", ai.text, ai.len);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment