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);
|
||||
char *aacenc_to_utf8(const char *s);
|
||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
||||
const char *aacenc_basename(const char *path);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,16 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -126,3 +126,15 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
|||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -649,7 +638,7 @@ 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;
|
||||
|
|
Loading…
Reference in New Issue