diff options
author | midipix <writeonce@midipix.org> | 2019-11-23 23:40:41 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2019-11-24 06:09:07 +0000 |
commit | bb09419950c72469316f1271cb8f3e56035b48cf (patch) | |
tree | 14a694b559b4d15649c0920fe13fc343997b039c /src/core | |
parent | 47891ed2b208b1edd88c7a119fc061e02fe575be (diff) | |
download | sltdl-bb09419950c72469316f1271cb8f3e56035b48cf.tar.bz2 sltdl-bb09419950c72469316f1271cb8f3e56035b48cf.tar.xz |
search path: lt_dlpathopen(): initial implementation.
Diffstat (limited to 'src/core')
-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); +} |