Skip to content

Commit 5164725

Browse files
committed
Detect directory prefixes properly with stat
1 parent 6d4d1b6 commit 5164725

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/axe.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#include "axe.h"
2626
#include "gsl_combination.h"
27+
#include <sys/types.h>
28+
#include <sys/stat.h>
29+
#include <unistd.h>
2730

2831
/* Holds the current timestamp, so we don't have to free the returned string
2932
* from now(). */
@@ -169,16 +172,15 @@ _axe_format_outfile_path (const char *prefix, const char *id, int read,
169172
char buf[4096];
170173
int res = 0;
171174
char *our_prefix = NULL;
172-
char lastchr = '\0';
173175
size_t prefix_len = 0;
176+
struct stat statbuff;
174177

175178
if (prefix == NULL || id == NULL) {
176179
return NULL;
177180
}
178181

179182
prefix_len = strlen(prefix);
180-
lastchr = prefix[prefix_len - 1];
181-
if (lastchr == '/' || lastchr == '\\') {
183+
if (stat(prefix, &statbuff) == 0 && S_ISDIR(statbuff.st_mode)) {
182184
/* Our prefix is a directory, don't add '_' */
183185
our_prefix = strdup(prefix);
184186
} else {

0 commit comments

Comments
 (0)