mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
fix bug where formatting of replaygain tags was affected by current locale
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "FLAC/assert.h"
|
#include "FLAC/assert.h"
|
||||||
#include "FLAC/file_decoder.h"
|
#include "FLAC/file_decoder.h"
|
||||||
#include "FLAC/metadata.h"
|
#include "FLAC/metadata.h"
|
||||||
|
#include <locale.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -76,6 +77,7 @@ static void set_file_stats_(const char *filename, struct stat *stats)
|
|||||||
static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, const FLAC__byte *name, float value)
|
static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, const FLAC__byte *name, float value)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
char *saved_locale;
|
||||||
FLAC__StreamMetadata_VorbisComment_Entry entry;
|
FLAC__StreamMetadata_VorbisComment_Entry entry;
|
||||||
|
|
||||||
FLAC__ASSERT(0 != block);
|
FLAC__ASSERT(0 != block);
|
||||||
@@ -84,11 +86,18 @@ static FLAC__bool append_tag_(FLAC__StreamMetadata *block, const char *format, c
|
|||||||
FLAC__ASSERT(0 != value);
|
FLAC__ASSERT(0 != value);
|
||||||
|
|
||||||
buffer[sizeof(buffer)-1] = '\0';
|
buffer[sizeof(buffer)-1] = '\0';
|
||||||
|
/*
|
||||||
|
* We need to save the old locale and switch to "C" because the locale
|
||||||
|
* influences the formatting of %f and we want it a certain way.
|
||||||
|
*/
|
||||||
|
saved_locale = setlocale(LC_ALL, 0);
|
||||||
|
setlocale(LC_ALL, "C");
|
||||||
#if defined _MSC_VER || defined __MINGW32__
|
#if defined _MSC_VER || defined __MINGW32__
|
||||||
_snprintf(buffer, sizeof(buffer)-1, format, name, value);
|
_snprintf(buffer, sizeof(buffer)-1, format, name, value);
|
||||||
#else
|
#else
|
||||||
snprintf(buffer, sizeof(buffer)-1, format, name, value);
|
snprintf(buffer, sizeof(buffer)-1, format, name, value);
|
||||||
#endif
|
#endif
|
||||||
|
setlocale(LC_ALL, saved_locale);
|
||||||
|
|
||||||
entry.entry = buffer;
|
entry.entry = buffer;
|
||||||
entry.length = strlen(buffer);
|
entry.length = strlen(buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user