From: nu774 Date: Thu, 10 Jan 2013 02:14:16 +0000 (+0900) Subject: rename basename() -> aacenc_basename() and move to compat layer X-Git-Tag: v0.0.9~1 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=5888fddccf0882e7738df13a918f296522034a77;p=fdkaac.git rename basename() -> aacenc_basename() and move to compat layer --- diff --git a/src/compat.h b/src/compat.h index f20f03f..07deb5b 100644 --- a/src/compat.h +++ b/src/compat.h @@ -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 diff --git a/src/compat_posix.c b/src/compat_posix.c index 1b8f14a..e101ff7 100644 --- a/src/compat_posix.c +++ b/src/compat_posix.c @@ -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) { diff --git a/src/compat_win32.c b/src/compat_win32.c index a68fa3f..6802730 100644 --- a/src/compat_win32.c +++ b/src/compat_win32.c @@ -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; +} diff --git a/src/main.c b/src/main.c index 4ee9487..458fe25 100644 --- a/src/main.c +++ b/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;