From f42084627b449996204810c61068505deffe77af Mon Sep 17 00:00:00 2001 From: David MacKenzie Date: Tue, 13 Jul 1993 00:54:45 +0000 Subject: * ldmain.c (set_scripts_dir): Check . and /../lib for ldscripts, as well as and SCRIPTDIR. --- ld/ChangeLog | 3 +++ ld/ldmain.c | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 7445fe3..46dadca 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,5 +1,8 @@ Mon Jul 12 11:45:48 1993 David J. Mackenzie (djm@thepub.cygnus.com) + * ldmain.c (set_scripts_dir): Check . and /../lib for + ldscripts, as well as and SCRIPTDIR. + * ldlang.c (lang_process): Use sizeof instead of magic constant. * ldmain.c (get_emulation, check_for_scripts_dir, diff --git a/ld/ldmain.c b/ld/ldmain.c index 111edea..9239c4a 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -338,36 +338,52 @@ check_for_scripts_dir (dir) sprintf (buf, "%s/ldscripts", dir); res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode); + free (buf); if (res) - { - buf[dirlen] = '\0'; - ldfile_add_library_path (buf); - } - else - free (buf); - + ldfile_add_library_path (dir); return res; } /* Set the default directory for finding script files. - Libraries will be searched for here too, but that's ok. */ + Libraries will be searched for here too, but that's ok. + We look for the "ldscripts" directory in: + + the curent dir + SCRIPTDIR (passed from Makefile) + the dir where this program is + the dir where this program is/../lib */ static void set_scripts_dir () { - char *end; + char *end, *dir; + size_t dirlen; + + if (check_for_scripts_dir (".")) + return; /* Newest version, most likely. */ if (check_for_scripts_dir (SCRIPTDIR)) - return; /* Good--we've been installed. */ + return; /* We've been installed normally. */ /* Look for "ldscripts" in the dir where our binary is. */ end = strrchr (program_name, '/'); if (!end) - return; /* Hope for the best. */ + return; + + /* Make a copy of program_name in dir. */ + dirlen = end - program_name; + dir = (char *) ldmalloc (dirlen + 8); /* Leave room for later "/../lib". */ + strncpy (dir, program_name, dirlen); + dir[dirlen] = '\0'; + if (check_for_scripts_dir (dir)) + return; /* Don't free dir. */ + + /* Look for "ldscripts" in /../lib. */ + strcpy (dir + dirlen, "/../lib"); + if (check_for_scripts_dir (dir)) + return; - *end = '\0'; - check_for_scripts_dir (program_name); - *end = '/'; + free (dir); /* Well, we tried. */ } void -- cgit v1.1