aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/main.c b/main.c
index 620ce3fdb35c..37889c3ff8fe 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.55 2015/07/11 00:34:19 tom Exp $ */
+/* $Id: main.c,v 1.56 2016/03/25 00:16:28 Jung-uk.Kim Exp $ */
#include <signal.h>
#ifndef _WIN32
@@ -410,32 +410,46 @@ alloc_file_name(size_t len, const char *suffix)
return result;
}
+static char *
+find_suffix(char *name, const char *suffix)
+{
+ size_t len = strlen(name);
+ size_t slen = strlen(suffix);
+ if (len >= slen)
+ {
+ name += len - slen;
+ if (strcmp(name, suffix) == 0)
+ return name;
+ }
+ return NULL;
+}
+
static void
create_file_names(void)
{
size_t len;
const char *defines_suffix;
const char *externs_suffix;
- char *prefix;
+ char *suffix;
- prefix = NULL;
+ suffix = NULL;
defines_suffix = DEFINES_SUFFIX;
externs_suffix = EXTERNS_SUFFIX;
/* compute the file_prefix from the user provided output_file_name */
if (output_file_name != 0)
{
- if (!(prefix = strstr(output_file_name, OUTPUT_SUFFIX))
- && (prefix = strstr(output_file_name, ".c")))
+ if (!(suffix = find_suffix(output_file_name, OUTPUT_SUFFIX))
+ && (suffix = find_suffix(output_file_name, ".c")))
{
defines_suffix = ".h";
externs_suffix = ".i";
}
}
- if (prefix != NULL)
+ if (suffix != NULL)
{
- len = (size_t) (prefix - output_file_name);
+ len = (size_t) (suffix - output_file_name);
file_prefix = TMALLOC(char, len + 1);
NO_SPACE(file_prefix);
strncpy(file_prefix, output_file_name, len)[len] = 0;
@@ -477,7 +491,7 @@ create_file_names(void)
CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX);
}
- if (prefix != NULL)
+ if (suffix != NULL)
{
FREE(file_prefix);
}