[syslinux:elflink] ldlinux: Use findpath() to lookup filenames

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Aug 14 09:21:08 PDT 2012


Commit-ID:  d1d03dee6bc961b0afd8dfc68fd35772ecded8be
Gitweb:     http://www.syslinux.org/commit/d1d03dee6bc961b0afd8dfc68fd35772ecded8be
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Tue, 7 Aug 2012 10:40:12 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Tue, 7 Aug 2012 10:40:12 +0100

ldlinux: Use findpath() to lookup filenames

We should use the same method of opening files as the module code when
searching for extensions. In particular, we should search all of PATH.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/ldlinux.c |    9 +++++----
 com32/include/sys/module.h      |    2 ++
 com32/lib/sys/module/common.c   |    2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index ade161f..1c261cd 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -83,19 +83,20 @@ static const char *get_extension(const char *kernel)
 	for (ext = file_extensions; ext->name; ext++) {
 		char *str;
 		int elen = strlen(ext->name);
-		int fd;
+		FILE *f;
 
 		str = malloc(len + elen + 1);
 
 		strncpy(str, kernel, len);
 		strncpy(str + len, ext->name, elen);
 		str[len + elen] = '\0';
-
-		fd = searchdir(str);
+		f = findpath(str);
 		free(str);
 
-		if (fd >= 0)
+		if (f) {
+			fclose(f);
 			return ext->name;
+		}
 	}
 
 	return NULL;
diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index 095eb97..ea11a88 100644
--- a/com32/include/sys/module.h
+++ b/com32/include/sys/module.h
@@ -146,6 +146,8 @@ struct module_dep {
  */
 extern struct elf_module *unload_modules_since(const char *name);
 
+extern FILE *findpath(char *name);
+
 
 #ifdef DYNAMIC_MODULE
 
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index b120bc7..6e63907 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -57,7 +57,7 @@ void print_elf_symbols(struct elf_module *module) {
 }
 #endif //ELF_DEBUG
 
-static FILE *findpath(char *name)
+FILE *findpath(char *name)
 {
 	char path[FILENAME_MAX];
 	FILE *f;


More information about the Syslinux-commits mailing list