export find_file function

git-svn-id: svn://svn.berlios.de/openocd/trunk@732 b42882b7-edfa-0310-969c-e2dbd0fdcd60
__archive__
oharboe 2008-06-27 06:20:41 +00:00
parent a61fe67b78
commit a78762e786
2 changed files with 25 additions and 10 deletions

View File

@ -54,17 +54,13 @@ void add_config_file_name (const char *cfg)
config_file_names[num_config_files] = NULL; 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; FILE *fp = NULL;
char **search_dirs = script_search_dirs; char **search_dirs = script_search_dirs;
char *dir; char *dir;
char const *mode="r";
char full_path[1024]; char full_path[1024];
/* Check absolute and relative to current working dir first. /* Check absolute and relative to current working dir first.
@ -84,8 +80,26 @@ FILE *open_file_from_path (char *file, char *mode)
} }
if (fp) if (fp)
LOG_DEBUG("opened %s", full_path); {
fclose(fp);
LOG_DEBUG("found %s", full_path);
return strdup(full_path);
}
return NULL;
}
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; return fp;
} }
} }

View File

@ -29,5 +29,6 @@ extern void add_config_file_name (const char *cfg);
extern void add_script_search_dir (const char *dir); extern void add_script_search_dir (const char *dir);
extern int configuration_output_handler(struct command_context_s *context, char* line); extern int configuration_output_handler(struct command_context_s *context, char* line);
extern FILE *open_file_from_path (char *file, char *mode); extern FILE *open_file_from_path (char *file, char *mode);
extern char *find_file(char *name);
#endif /* CONFIGURATION_H */ #endif /* CONFIGURATION_H */