Skip to content

Commit aa672c6

Browse files
committed
Updating the ccpp_ipd library finding function.
You can now specify a path (relative or absolute) to the scheme library file in the xml "lib" attribute. If CCPP can stat() that file, it will dlopen() it.
1 parent cb37c8c commit aa672c6

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/ccpp_ipd.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <dlfcn.h>
2828
#include <err.h>
2929
#include <sysexits.h>
30+
#include <sys/types.h>
31+
#include <sys/stat.h>
32+
#include <unistd.h>
3033

3134
#include "ccpp_ipd.h"
3235

@@ -56,19 +59,27 @@ ccpp_ipd_open(const char *scheme, const char *lib, const char *ver,
5659
int i = 0;
5760
int n = 0;
5861
const char cap[] = "_cap";
62+
const char *l = NULL;
5963
char *library = NULL;
6064
char *scheme_cap = NULL;
6165
char *error = NULL;
66+
struct stat sbuf = {0};
6267

63-
/* Generate the library name with the platform suffix */
64-
n = (strlen(prefix) + strlen(lib) + strlen(suffix) + strlen(ver) +2)
65-
*sizeof(char);
66-
library = malloc(n);
67-
memset(library, 0, n);
68-
if (strcmp(ver, "") != 0) {
69-
snprintf(library, n, "%s%s.%s%s", prefix, lib, ver, suffix);
68+
/* Did we get an actual library file? */
69+
if (stat(lib, &sbuf) == 0) {
70+
l = lib;
7071
} else {
71-
snprintf(library, n, "%s%s%s", prefix, lib, suffix);
72+
/* Generate the library name with the platform suffix */
73+
n = (strlen(prefix) + strlen(lib) + strlen(suffix) + strlen(ver) +2)
74+
*sizeof(char);
75+
library = malloc(n);
76+
memset(library, 0, n);
77+
if (strcmp(ver, "") != 0) {
78+
snprintf(library, n, "%s%s.%s%s", prefix, lib, ver, suffix);
79+
} else {
80+
snprintf(library, n, "%s%s%s", prefix, lib, suffix);
81+
}
82+
l = library;
7283
}
7384

7485
/* Generate the scheme cap function name */
@@ -83,16 +94,13 @@ ccpp_ipd_open(const char *scheme, const char *lib, const char *ver,
8394
strncat(scheme_cap, cap, n);
8495

8596
/* Open a handle to the library */
86-
*lhdl = dlopen(library, RTLD_NOW);
97+
*lhdl = dlopen(l, RTLD_NOW);
8798
if (!*lhdl) {
8899
warnx("%s", dlerror());
89100
return(EXIT_FAILURE);
90101
}
91102

92103
dlerror();
93-
/*
94-
*(void **)(&(*shdl)) = dlsym(*lhdl, scheme_cap);
95-
*/
96104
*(void **)shdl = dlsym(*lhdl, scheme_cap);
97105
if ((error = dlerror()) != NULL) {
98106
warnx("%s", error);

0 commit comments

Comments
 (0)