flac: Input file name size calculated just one time

This commit is contained in:
Andrey Astafyev 2019-11-30 05:08:58 +03:00 committed by Erik de Castro Lopo
parent a76bdaab67
commit a9d9f4d353

View File

@ -1694,6 +1694,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
const char *outfilename = get_encoded_outfilename(infilename); /* the final name of the encoded file */
/* internal_outfilename is the file we will actually write to; it will be a temporary name if infilename==outfilename */
char *internal_outfilename = 0; /* NULL implies 'use outfilename' */
size_t infilename_length;
if(0 == outfilename) {
flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename);
@ -1714,21 +1715,22 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
if(!option_values.force_raw_format) {
/* first set format based on name */
if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".wav"))
infilename_length = strlen(infilename);
if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".wav"))
input_format = FORMAT_WAVE;
else if(strlen(infilename) >= 5 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-5), ".rf64"))
else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".rf64"))
input_format = FORMAT_RF64;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".w64"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".w64"))
input_format = FORMAT_WAVE64;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".aif"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".aif"))
input_format = FORMAT_AIFF;
else if(strlen(infilename) >= 5 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-5), ".aiff"))
else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".aiff"))
input_format = FORMAT_AIFF;
else if(strlen(infilename) >= 5 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-5), ".flac"))
else if(infilename_length >= 5 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-5), ".flac"))
input_format = FORMAT_FLAC;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".oga"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".oga"))
input_format = FORMAT_OGGFLAC;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".ogg"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".ogg"))
input_format = FORMAT_OGGFLAC;
/* attempt to guess the file type based on the first 12 bytes */
@ -2036,6 +2038,7 @@ int decode_file(const char *infilename)
FileFormat output_format = FORMAT_WAVE;
decode_options_t decode_options;
const char *outfilename = get_decoded_outfilename(infilename);
size_t infilename_length;
if(0 == outfilename) {
flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename);
@ -2084,11 +2087,12 @@ int decode_file(const char *infilename)
return usage_error("ERROR: --keep-foreign-metadata can only be used with WAVE, Wave64, RF64, or AIFF output\n");
}
infilename_length = strlen(infilename);
if(option_values.use_ogg)
treat_as_ogg = true;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".oga"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".oga"))
treat_as_ogg = true;
else if(strlen(infilename) >= 4 && 0 == FLAC__STRCASECMP(infilename+(strlen(infilename)-4), ".ogg"))
else if(infilename_length >= 4 && 0 == FLAC__STRCASECMP(infilename+(infilename_length-4), ".ogg"))
treat_as_ogg = true;
else
treat_as_ogg = false;