PATH = malloc(strlen(CurrentDirName) + 1);
if (!PATH) {
printf("Couldn't allocate memory for PATH\n");
- return;
+ goto out;
}
strcpy(PATH, CurrentDirName);
* a bit harder to find LDLINUX. If search_dirs() succeeds
* in finding LDLINUX it will set the cwd.
*/
+ free(PATH);
fd = opendev(&__file_dev, NULL, O_RDONLY);
if (fd < 0)
return;
fp = &__file_info[fd];
- if (!search_dirs(&fp->i.fd, search_directories, filenames, realname))
+ if (!search_dirs(&fp->i.fd, search_directories, filenames, realname)) {
+ char path[FILENAME_MAX];
+
+ /*
+ * search_dirs() sets the current working directory if
+ * it successfully opens the file. Set PATH to the
+ * directory in which we found ldlinux.c32.
+ */
+ if (!core_getcwd(path, sizeof(path)))
+ goto out;
+
+ PATH = malloc(strlen(path) + 1);
+ if (!PATH) {
+ printf("Couldn't allocate memory for PATH\n");
+ goto out;
+ }
+
+ strcpy(PATH, path);
+
start_ldlinux(argv);
+ }
+out:
writestr("\nFailed to load ldlinux.c32");
}