void aacenc_getmainargs(int *argc, char ***argv);
char *aacenc_to_utf8(const char *s);
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
+const char *aacenc_basename(const char *path);
#endif
return cnt;
}
+/*
+ * Different from POSIX basename() when path ends with /.
+ * Since we use this only for a regular file, the difference doesn't matter.
+ */
+const char *aacenc_basename(const char *path)
+{
+ const char *p = strrchr(path, '/');
+ return p ? p + 1: path;
+}
+
#ifndef HAVE_ICONV
char *aacenc_to_utf8(const char *s)
{
return cnt;
}
+const char *aacenc_basename(const char *path)
+{
+/*
+ * Since path is encoded with UTF-8, naive usage of strrchr() shoule be safe.
+ */
+ const char *p = strrchr(path, '/');
+ const char *q = strrchr(path, '\\');
+ const char *r = strrchr(path, ':');
+ if (q > p) p = q;
+ if (r > p) p = r;
+ return p ? p + 1 : path;
+}
return 0;
}
-static
-const char *basename(const char *filename)
-{
- char *p = strrchr(filename, '/');
-#ifdef _WIN32
- char *q = strrchr(filename, '\\');
- if (p < q) p = q;
-#endif
- return p ? p + 1 : filename;
-}
-
static
char *generate_output_filename(const char *filename, const char *ext)
{
p = malloc(ext_len + 6);
sprintf(p, "stdin%s", ext);
} else {
- const char *base = basename(filename);
+ const char *base = aacenc_basename(filename);
size_t ilen = strlen(base);
const char *ext_org = strrchr(base, '.');
if (ext_org) ilen = ext_org - base;