diff options
author | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-11-21 23:29:58 +0100 |
---|---|---|
committer | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-11-22 13:38:42 +0100 |
commit | 700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a (patch) | |
tree | 6e97e94d32ece999962c6135f01b8bd1c6dae741 | |
parent | 964c3639e2464b18d72f16fa175fee9beb843b36 (diff) | |
download | openocd+libswd-700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a.tar.gz openocd+libswd-700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a.tar.bz2 openocd+libswd-700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a.tar.xz openocd+libswd-700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a.zip |
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>
-rw-r--r-- | src/helper/configuration.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/helper/configuration.c b/src/helper/configuration.c index 2ea5da48..007246c5 100644 --- a/src/helper/configuration.c +++ b/src/helper/configuration.c @@ -61,21 +61,23 @@ char *find_file(const char *file) char **search_dirs = script_search_dirs; char *dir; char const *mode="r"; - char full_path[1024]; + char *full_path; /* Check absolute and relative to current working dir first. * This keeps full_path reporting belowing working. */ - snprintf(full_path, 1024, "%s", file); + full_path = alloc_printf("%s", file); fp = fopen(full_path, mode); while (!fp) { + free(full_path); + full_path = NULL; dir = *search_dirs++; if (!dir) break; - snprintf(full_path, 1024, "%s/%s", dir, file); + full_path = alloc_printf("%s/%s", dir, file); fp = fopen(full_path, mode); } @@ -83,8 +85,11 @@ char *find_file(const char *file) { fclose(fp); LOG_DEBUG("found %s", full_path); - return strdup(full_path); + return full_path; } + + free(full_path); + return NULL; } |