summaryrefslogtreecommitdiff
path: root/src/helper/configuration.c
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-06-27 06:20:41 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-06-27 06:20:41 +0000
commita78762e786bd21d6fc855e23bf87036369582316 (patch)
tree1f614b7c470ca987acafa17efb20818d30fb48e4 /src/helper/configuration.c
parenta61fe67b78f6436703a51242e03d5c115ea27cf9 (diff)
downloadopenocd+libswd-a78762e786bd21d6fc855e23bf87036369582316.tar.gz
openocd+libswd-a78762e786bd21d6fc855e23bf87036369582316.tar.bz2
openocd+libswd-a78762e786bd21d6fc855e23bf87036369582316.tar.xz
openocd+libswd-a78762e786bd21d6fc855e23bf87036369582316.zip
export find_file function
git-svn-id: svn://svn.berlios.de/openocd/trunk@732 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/helper/configuration.c')
-rw-r--r--src/helper/configuration.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/helper/configuration.c b/src/helper/configuration.c
index 2d84d9e6..68c863f3 100644
--- a/src/helper/configuration.c
+++ b/src/helper/configuration.c
@@ -54,17 +54,13 @@ void add_config_file_name (const char *cfg)
config_file_names[num_config_files] = NULL;
}
-FILE *open_file_from_path (char *file, char *mode)
+/* return full path or NULL according to search rules */
+char *find_file(char *file)
{
- if (mode[0]!='r')
- {
- return fopen(file, mode);
- } else
- {
-
FILE *fp = NULL;
char **search_dirs = script_search_dirs;
char *dir;
+ char const *mode="r";
char full_path[1024];
/* Check absolute and relative to current working dir first.
@@ -82,11 +78,29 @@ FILE *open_file_from_path (char *file, char *mode)
snprintf(full_path, 1024, "%s/%s", dir, file);
fp = fopen(full_path, mode);
}
-
+
if (fp)
- LOG_DEBUG("opened %s", full_path);
+ {
+ fclose(fp);
+ LOG_DEBUG("found %s", full_path);
+ return strdup(full_path);
+ }
+ return NULL;
+}
- return fp;
+
+FILE *open_file_from_path (char *file, char *mode)
+{
+ if (mode[0]!='r')
+ {
+ return fopen(file, mode);
+ } else
+ {
+ char *full_path=find_file(file);
+ FILE *fp = NULL;
+ fp = fopen(full_path, mode);
+ free(full_path);
+ return fp;
}
}