export find_file function
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 27 Jun 2008 06:20:41 +0000 (06:20 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 27 Jun 2008 06:20:41 +0000 (06:20 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@732 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/configuration.c
src/helper/configuration.h

index 2d84d9e60e3e9feac3b3bfe0fa9bb6b88c02114f..68c863f3253ca9278fdae5330d84063e8a4f78df 100644 (file)
@@ -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;
        }
 }
 
index ff802758fcca0546aa1fbd03d8f85c387877156e..d2e30e77d1aff722a78dc921f9ab49da285da213 100644 (file)
@@ -29,5 +29,6 @@ extern void add_config_file_name (const char *cfg);
 extern void add_script_search_dir (const char *dir);
 extern int configuration_output_handler(struct command_context_s *context, char* line);
 extern FILE *open_file_from_path (char *file, char *mode);
+extern char *find_file(char *name);
 
 #endif /* CONFIGURATION_H */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)