Implement support for LD_PRELOAD in the dynamic linker.

Submitted by:	Doug Ambrisko <ambrisko@ambrisko.roble.com>
This commit is contained in:
jdp 1996-04-20 18:27:56 +00:00
parent 6a1af9771c
commit beba335ecb
3 changed files with 56 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: ld.h,v 1.14 1995/05/30 05:01:45 rgrimes Exp $
* $Id: ld.h,v 1.15 1996/01/13 00:14:52 jdp Exp $
*/
/*-
* This code is derived from software copyrighted by the Free Software
@ -643,6 +643,7 @@ int findlib __P((struct file_entry *));
/* In shlib.c: */
char *findshlib __P((char *, int *, int *, int));
char *find_lib_file __P((char *));
char *search_lib_dir __P((char *, char *, int *, int *, int));
void add_search_dir __P((char *));
void add_search_path __P((char *));

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: shlib.c,v 1.13 1995/03/19 21:20:09 nate Exp $
* $Id: shlib.c,v 1.14 1996/01/13 00:14:53 jdp Exp $
*/
#include <sys/param.h>
@ -203,6 +203,32 @@ int do_dot_a;
return NULL;
}
/*
* Search library directories for a file with the given name. The
* return value is a full pathname to the matching file. The string
* is dynamically allocated. If no matching file is found, the function
* returns NULL.
*/
char *
find_lib_file(name)
char *name;
{
int i;
for (i = 0; i < n_search_dirs; i++) {
char *path = concat(search_dirs[i], "/", name);
struct stat sb;
if (lstat(path, &sb) != -1) /* We found it */
return path;
free(path);
}
return NULL;
}
/*
* Search a given directory for a library (preferably shared) satisfying
* the given criteria.

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: shlib.c,v 1.13 1995/03/19 21:20:09 nate Exp $
* $Id: shlib.c,v 1.14 1996/01/13 00:14:53 jdp Exp $
*/
#include <sys/param.h>
@ -203,6 +203,32 @@ int do_dot_a;
return NULL;
}
/*
* Search library directories for a file with the given name. The
* return value is a full pathname to the matching file. The string
* is dynamically allocated. If no matching file is found, the function
* returns NULL.
*/
char *
find_lib_file(name)
char *name;
{
int i;
for (i = 0; i < n_search_dirs; i++) {
char *path = concat(search_dirs[i], "/", name);
struct stat sb;
if (lstat(path, &sb) != -1) /* We found it */
return path;
free(path);
}
return NULL;
}
/*
* Search a given directory for a library (preferably shared) satisfying
* the given criteria.