embedded: reduce stack usage

Allocate working structures on stack to avoid issues with
path lengths + reduce stack usage.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
This commit is contained in:
Øyvind Harboe 2009-11-21 23:29:58 +01:00
parent 964c3639e2
commit 700a60ec57
1 changed files with 9 additions and 4 deletions

View File

@ -61,21 +61,23 @@ char *find_file(const char *file)
char **search_dirs = script_search_dirs; char **search_dirs = script_search_dirs;
char *dir; char *dir;
char const *mode="r"; char const *mode="r";
char full_path[1024]; char *full_path;
/* Check absolute and relative to current working dir first. /* Check absolute and relative to current working dir first.
* This keeps full_path reporting belowing working. */ * This keeps full_path reporting belowing working. */
snprintf(full_path, 1024, "%s", file); full_path = alloc_printf("%s", file);
fp = fopen(full_path, mode); fp = fopen(full_path, mode);
while (!fp) while (!fp)
{ {
free(full_path);
full_path = NULL;
dir = *search_dirs++; dir = *search_dirs++;
if (!dir) if (!dir)
break; break;
snprintf(full_path, 1024, "%s/%s", dir, file); full_path = alloc_printf("%s/%s", dir, file);
fp = fopen(full_path, mode); fp = fopen(full_path, mode);
} }
@ -83,8 +85,11 @@ char *find_file(const char *file)
{ {
fclose(fp); fclose(fp);
LOG_DEBUG("found %s", full_path); LOG_DEBUG("found %s", full_path);
return strdup(full_path); return full_path;
} }
free(full_path);
return NULL; return NULL;
} }