public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* overriding defaults with register_printf_function
@ 2007-04-18 15:42 a.w. kinnunen
  0 siblings, 0 replies; only message in thread
From: a.w. kinnunen @ 2007-04-18 15:42 UTC (permalink / raw)
  To: glibc-bugs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-18 15:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-18 15:42 overriding defaults with register_printf_function a.w. kinnunen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).