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

The bug was introduced by 9dfe50f1d.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2020-06-29 07:23:16 +09:00
parent 233cb49903
commit ac8360003e
+19 -6
View File
@@ -52,14 +52,27 @@ usage(const char *name)
static char *
get_outfilename(mrb_state *mrb, char *infile, const char *ext)
{
size_t infilelen;
size_t flen;
size_t ilen, flen, elen;
char *outfile;
char *p = NULL;
infilelen = strlen(infile);
flen = infilelen + strlen(ext) + 1;
outfile = (char*)mrb_malloc(mrb, flen);
snprintf(outfile, flen, "%s%s", infile, ext);
ilen = strlen(infile);
flen = ilen;
if (*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;
}