Skip to content

Commit

Permalink
Don't add an '_' to file names if prefix is a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
kdm9 committed Jun 1, 2015
1 parent 74fd7b9 commit 7b1a451
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/axe.c
Expand Up @@ -162,18 +162,37 @@ _axe_format_outfile_path (const char *prefix, const char *id, int read,
{
char buf[4096];
int res = 0;
char *our_prefix = NULL;
char lastchr = '\0';
size_t prefix_len = 0;

if (prefix == NULL || id == NULL) {
return NULL;
}

prefix_len = strlen(prefix);
lastchr = prefix[prefix_len - 1];
if (lastchr == '/' || lastchr == '\\') {
/* Our prefix is a directory, don't add '_' */
our_prefix = strdup(prefix);
} else {
/* Duplicate and append an underscore to prefix */
our_prefix = qes_malloc(prefix_len + 2);
our_prefix[prefix_len + 1] = '\0';
strncpy(our_prefix, prefix, prefix_len);
our_prefix[prefix_len] = '_';
}

if (read > 0) {
res = snprintf(buf, 4096, "%s_%s_R%d.%s", prefix, id, read, ext);
res = snprintf(buf, 4096, "%s%s_R%d.%s", our_prefix, id, read, ext);
} else {
res = snprintf(buf, 4096, "%s_%s_il.%s", prefix, id, ext);
res = snprintf(buf, 4096, "%s%s_il.%s", our_prefix, id, ext);
}
if (res >= 4096) {
qes_free(our_prefix);
return NULL;
}
qes_free(our_prefix);
return strndup(buf, 4096);
}

Expand Down

0 comments on commit 7b1a451

Please sign in to comment.