mirror of https://github.com/nu774/fdkaac.git
rename basename() -> aacenc_basename() and move to compat layer
This commit is contained in:
parent
c5c459082a
commit
5888fddccf
|
@ -20,5 +20,6 @@ FILE *aacenc_fopen(const char *name, const char *mode);
|
||||||
void aacenc_getmainargs(int *argc, char ***argv);
|
void aacenc_getmainargs(int *argc, char ***argv);
|
||||||
char *aacenc_to_utf8(const char *s);
|
char *aacenc_to_utf8(const char *s);
|
||||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
||||||
|
const char *aacenc_basename(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,6 +48,16 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||||
return cnt;
|
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
|
#ifndef HAVE_ICONV
|
||||||
char *aacenc_to_utf8(const char *s)
|
char *aacenc_to_utf8(const char *s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -126,3 +126,15 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||||
return cnt;
|
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;
|
||||||
|
}
|
||||||
|
|
13
src/main.c
13
src/main.c
|
@ -628,17 +628,6 @@ int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||||
return 0;
|
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
|
static
|
||||||
char *generate_output_filename(const char *filename, const char *ext)
|
char *generate_output_filename(const char *filename, const char *ext)
|
||||||
{
|
{
|
||||||
|
@ -649,7 +638,7 @@ char *generate_output_filename(const char *filename, const char *ext)
|
||||||
p = malloc(ext_len + 6);
|
p = malloc(ext_len + 6);
|
||||||
sprintf(p, "stdin%s", ext);
|
sprintf(p, "stdin%s", ext);
|
||||||
} else {
|
} else {
|
||||||
const char *base = basename(filename);
|
const char *base = aacenc_basename(filename);
|
||||||
size_t ilen = strlen(base);
|
size_t ilen = strlen(base);
|
||||||
const char *ext_org = strrchr(base, '.');
|
const char *ext_org = strrchr(base, '.');
|
||||||
if (ext_org) ilen = ext_org - base;
|
if (ext_org) ilen = ext_org - base;
|
||||||
|
|
Loading…
Reference in New Issue