diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lt_path.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/core/lt_path.c b/src/core/lt_path.c index 14eb0eb..5d58b03 100644 --- a/src/core/lt_path.c +++ b/src/core/lt_path.c @@ -5,9 +5,11 @@ /*******************************************************************/ #include <limits.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <pthread.h> #include <sltdl/sltdl.h> #include "sltdl_core.h" @@ -240,3 +242,48 @@ int lt_dlinsertsearchdir(const char * mark, const char * path) return lt_sunlock(ret); } + +int lt_dlpathopen(const char * module, const char ** extv) +{ + int fdat; + int fdmod; + char ** ppath; + const char ** pext; + size_t mlen; + size_t elen; + char path[1024]; + + if ((mlen = strlen(module)) >= sizeof(path)) + return -1; + + memcpy(path,module,mlen); + + lt_slock(); + + for (ppath=lt_pathv; *ppath; ppath++) { + fdat = open(*ppath,O_RDONLY|O_DIRECTORY|O_CLOEXEC,0); + + if (fdat >= 0) { + for (pext=extv; *pext; pext++) { + if (mlen + (elen = strlen(*pext)) >= (sizeof(path))) { + close(fdat); + return (-1); + } + + memcpy(&path[mlen],*pext,elen); + path[mlen+elen] = 0; + + fdmod = openat(fdat,path,O_EXEC|O_CLOEXEC,0); + + if (fdmod >= 0) { + close(fdat); + return lt_sunlock(fdmod); + } + } + + close(fdat); + } + } + + return lt_sunlock(-1); +} |