[Live-devel] sprintf and radix char.
Derk-Jan Hartman
hartman at videolan.org
Thu Oct 27 02:53:34 PDT 2005
On 23-aug-2005, at 20:17, Ross Finlayson wrote:
>> fenrir ran into an interesting problem. RTSPClient.cpp uses sprintf
>> to create the Range: header. However the radix character used when
>> printing a float with sprintf (as createRangeString uses), is locale
>> dependent. However Range needs to use . as radix character.
>
> Interesting...
>
>> I gather there is probably more then one area where this might go
>> wrong.
>
> Yes, it seems that both "RTSPClient" and "RTSPServer" need to be
> modified in the places where they output (and parse!) the RTSP
> "Range:" and "Scale:" headers. (I think those are the only fields
> where floats are currently used.)
>
> I'll add this fix to the next release of the code.
He Ross,
I thought this was working, but in recent weeks we got reports it
wasn't. We tried all sorts of things, but it wasn't coming together.
In the end we had to resolve to plain C code, and that WAS working. I
suspect the only way to do this is having the locale code and the
sprintf in the same local Class scope or something.
I suggest simply adding something like:
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
int radix_safe_sprintf( char *str, const char *format, ...)
{
va_list args;
int result = 0;
char *locale = NULL;
locale = strDup( setlocale( LC_NUMERIC, NULL ) );
setlocale( LC_NUMERIC, "C" );
va_start( args, psz_format );
result = vsprintf(str, format, args );
va_end( args );
setlocale( LC_NUMERIC, locale );
delete[] locale;
return result;
}
And similar for sscanf
int radix_safe_vsscanf( const char *str, const char *format, ...)
{
va_list args;
int result = 0;
char *locale = NULL;
locale = strDup( setlocale( LC_NUMERIC, NULL ) );
setlocale( LC_NUMERIC, "C" );
va_start( args, psz_format );
result = vsscanf(str, format, args );
va_end( args );
setlocale( LC_NUMERIC, locale );
delete[] locale;
return result;
}
More information about the live-devel
mailing list