66#include "isend.h"
77#include "internal.h"
88#include "sync.h"
9+ #include "config.h" // for HAVE_USELOCALE
910
1011#include <stdarg.h>
1112#include <limits.h>
1213#include <stdio.h>
1314
15+ #ifdef HAVE_USELOCALE
16+ #include <locale.h>
17+ #endif
18+
1419/* (bits+1)/3 (plus the sign character) */
1520enum {
1621 INTLEN = (sizeof (int ) * CHAR_BIT + 1 ) / 3 + 1 ,
@@ -31,11 +36,22 @@ format_range(char *buffer, size_t size, unsigned start, unsigned end)
3136static void
3237format_frange (char * buffer , size_t size , float start , float end )
3338{
39+ #ifdef HAVE_USELOCALE
40+ // use the POSIX locale to format floating point numbers
41+ const locale_t my_locale = newlocale (LC_NUMERIC_MASK , "C" , NULL );
42+ const locale_t old_locale = uselocale (my_locale );
43+ #endif
44+
3445 /* the special value 0.0 means "open range" */
3546 if (end >= 0 )
3647 snprintf (buffer , size , "%1.3f:%1.3f" , (double )start , (double )end );
3748 else
3849 snprintf (buffer , size , "%1.3f:" , (double )start );
50+
51+ #ifdef HAVE_USELOCALE
52+ uselocale (old_locale );
53+ freelocale (my_locale );
54+ #endif
3955}
4056
4157/**
@@ -153,9 +169,20 @@ bool
153169mpd_send_float_command (struct mpd_connection * connection , const char * command ,
154170 float arg )
155171{
156- char arg_string [FLOATLEN ];
172+ #ifdef HAVE_USELOCALE
173+ // use the POSIX locale to format floating point numbers
174+ const locale_t my_locale = newlocale (LC_NUMERIC_MASK , "C" , NULL );
175+ const locale_t old_locale = uselocale (my_locale );
176+ #endif
157177
178+ char arg_string [FLOATLEN ];
158179 snprintf (arg_string , sizeof (arg_string ), "%f" , (double )arg );
180+
181+ #ifdef HAVE_USELOCALE
182+ uselocale (old_locale );
183+ freelocale (my_locale );
184+ #endif
185+
159186 return mpd_send_command (connection , command , arg_string , NULL );
160187}
161188
@@ -187,10 +214,22 @@ bool
187214mpd_send_u_f_command (struct mpd_connection * connection , const char * command ,
188215 unsigned arg1 , float arg2 )
189216{
217+ #ifdef HAVE_USELOCALE
218+ // use the POSIX locale to format floating point numbers
219+ const locale_t my_locale = newlocale (LC_NUMERIC_MASK , "C" , NULL );
220+ const locale_t old_locale = uselocale (my_locale );
221+ #endif
222+
190223 char arg1_string [INTLEN ], arg2_string [FLOATLEN ];
191224
192225 snprintf (arg1_string , sizeof (arg1_string ), "%u" , arg1 );
193226 snprintf (arg2_string , sizeof (arg2_string ), "%.3f" , (double )arg2 );
227+
228+ #ifdef HAVE_USELOCALE
229+ uselocale (old_locale );
230+ freelocale (my_locale );
231+ #endif
232+
194233 return mpd_send_command (connection , command ,
195234 arg1_string , arg2_string , NULL );
196235}
0 commit comments