Set stdin/stdout to binary on Windows for binary input/output

Also fix tests on Windows
This commit is contained in:
Martijn van Beurden 2023-02-20 08:12:48 +01:00
parent c10b059588
commit 6633d2f9bf
2 changed files with 30 additions and 3 deletions

View File

@ -255,6 +255,10 @@ FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const Command
break;
}
#ifdef _WIN32
_setmode(fileno(stdin),_O_BINARY);
#endif
/* Read header from stdin */
while(fread(header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, stdin) == FLAC__STREAM_METADATA_HEADER_LENGTH) {
@ -315,6 +319,10 @@ FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const Command
}
}
#ifdef _WIN32
_setmode(fileno(stdin),_O_TEXT);
#endif
if(num_objects == 0)
flac_fprintf(stderr, "ERROR: unable to find a metadata block in the supplied input\n");
@ -795,10 +803,18 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
void write_metadata_binary(FLAC__StreamMetadata *block, FLAC__byte *block_raw, FLAC__bool headerless)
{
#ifdef _WIN32
fflush(stdout);
_setmode(fileno(stdout),_O_BINARY);
#endif
if(!headerless)
local_fwrite(block_raw, 1, block->length+FLAC__STREAM_METADATA_HEADER_LENGTH, stdout);
else if(block->type == FLAC__METADATA_TYPE_APPLICATION && block->length > 3)
local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH+4, 1, block->length-4, stdout);
else
local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH, 1, block->length, stdout);
#ifdef _WIN32
fflush(stdout);
_setmode(fileno(stdout),_O_TEXT);
#endif
}

View File

@ -124,6 +124,18 @@ metaflac_test ()
echo OK
}
metaflac_test_nofilter ()
{
case="$testdatadir/$1"
desc="$2"
args="$3"
expect="$case-expect.meta"
echo $ECHO_N "test $1: $desc... " $ECHO_C
run_metaflac $args $flacfile > $testdir/out.meta || die "ERROR running metaflac"
diff -w $expect $testdir/out.meta || die "ERROR: metadata does not match expected $expect"
echo OK
}
metaflac_test_binary ()
{
case="$testdatadir/$1"
@ -133,7 +145,6 @@ metaflac_test_binary ()
echo $ECHO_N "test $1: $desc... " $ECHO_C
run_metaflac $args $flacfile > $testdir/out.meta || die "ERROR running metaflac"
cmp $expect $testdir/out.meta || die "ERROR: metadata does not match expected $expect"
# To blindly accept (and check later): cp -f $testdir/out.meta $expect
echo OK
}
@ -454,7 +465,7 @@ else
die "ERROR, couldn't add vorbis comment metadata block"
fi
metaflac_test_binary case66 "--append" "--list"
metaflac_test_nofilter case66 "--append" "--list"
if run_metaflac_to_metaflac_silent "--list --data-format=binary --except-block-type=STREAMINFO,SEEKTABLE,VORBIS_COMMENT $flacfile2" "--append --block-number=0 $flacfile" ; then
:
@ -462,6 +473,6 @@ else
die "ERROR, couldn't add vorbis comment metadata block"
fi
metaflac_test_binary case67 "--append --block-number=0" "--list"
metaflac_test_nofilter case67 "--append --block-number=0" "--list"
rm -f metaflac-test-files/out.meta metaflac-test-files/out1.meta