Fix the bug that `mrbc` generates `a.rb.mrb` instead of `a.mrb`.

The bug was introduced by 9dfe50f1.
parent 233cb499
...@@ -52,14 +52,27 @@ usage(const char *name) ...@@ -52,14 +52,27 @@ usage(const char *name)
static char * static char *
get_outfilename(mrb_state *mrb, char *infile, const char *ext) get_outfilename(mrb_state *mrb, char *infile, const char *ext)
{ {
size_t infilelen; size_t ilen, flen, elen;
size_t flen;
char *outfile; char *outfile;
char *p = NULL;
infilelen = strlen(infile); ilen = strlen(infile);
flen = infilelen + strlen(ext) + 1; flen = ilen;
outfile = (char*)mrb_malloc(mrb, flen); if (*ext) {
snprintf(outfile, flen, "%s%s", infile, ext); elen = strlen(ext);
if ((p = strrchr(infile, '.'))) {
ilen = p - infile;
}
flen += elen;
}
else {
flen = ilen;
}
outfile = (char*)mrb_malloc(mrb, flen+1);
strncpy(outfile, infile, ilen+1);
if (p) {
strncpy(outfile+ilen, ext, elen+1);
}
return outfile; return outfile;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment