overriding defaults with register_printf_function

a.w. kinnunen a.w.kinnunen@gmail.com
Wed Apr 18 15:42:00 GMT 2007


Hi!

Here's a bug I suppose. libc manual says in

12.13.1 Registering New Conversions :
...You can redefine the built-in conversions like `%s',...

but it doesn't seems to work. I'm porting an application to linux, and
I need to maintain non-unicode+windows support. This happens with
glibc-2.3.5-0ubuntu1

Here's the code, it won't compile for as it is but you'll get the point:

#ifdef _UNICODE
/*
    these can be used to redefine %s and %S to work
    in windows style,

    they need to be registered using register_printfs;
*/
int print_char_callback( FILE *stream,
                        const struct printf_info *info_box, const void
*const *args){

    const char *chr;
    chr = *((const char **) (args[0]));
    return fprintf( stream, "%ls", char_to_TCHAR(chr));
}
int print_wchar_callback( FILE *stream,
                        const struct printf_info *info_box, const void
*const *args){
    const TCHAR *chr;
    chr = *((const TCHAR **) (args[0]));
    return fprintf( stream, "%ls", chr);
}
int printf_wchars_arginfo( const struct printf_info *info, size_t n,
int *argtypes ){
    if (n > 0)
        argtypes[0] =  PA_WSTRING;
    return 1;
}

void register_printfs(){
// these work if I printf with %y
//    register_printf_function('Y', print_char_callback, printf_wchars_arginfo);
//    register_printf_function('y', print_wchar_callback,
printf_wchars_arginfo);

// and these below won't just work
    register_printf_function('S', print_char_callback, printf_wchars_arginfo);
    register_printf_function('s', print_wchar_callback, printf_wchars_arginfo);
}
#endif



More information about the Glibc-bugs mailing list