Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dlfcn.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <dirent.h>
- #include <stdlib.h>
- #include <string.h>
- struct Parametrs {
- int arg[16];
- };
- int main(int argc, char *argv[]) {
- struct Parametrs st;
- const char *types = argv[3];
- int arg = 4, counter = 0;
- void *handle = dlopen(argv[1], RTLD_NOW);
- if (!handle) {
- exit(1);
- }
- void *func = dlsym(handle, argv[2]);
- if (!func) {
- exit(1);
- }
- for (const char *p = types + 1; *p; ++p) {
- if (*p == 'd') {
- counter += 1;
- double val = strtod(argv[arg],NULL);
- memcpy(&st.arg[counter], &val, sizeof(val));
- } else if (*p == 's') {
- st.arg[counter] = (int) argv[arg];
- } else if (*p == 'i') {
- int val = atoi(argv[arg]);
- st.arg[counter] = val;
- }
- ++counter; ++arg;
- }
- if (types[0] == 'd') {
- double result = (*(double (*)(struct Parametrs)) func)(st);
- printf("%.10g\n", result);
- } else if (types[0] == 's') {
- char *result = (*(char * (*)(struct Parametrs)) func)(st);
- printf("%s\n", result);
- } else if (types[0] == 'i') {
- int result = (*(int (*)(struct Parametrs)) func)(st);
- printf("%d\n", result);
- } else {
- (*(void (*)(struct Parametrs)) func)(st);
- }
- dlclose(handle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement