Use register_printf_specifier instead of deprecated register_printf_function, if available

This commit is contained in:
Martin Willi
2009-11-12 13:16:46 +01:00
parent 0850e33518
commit f6bbcec390
3 changed files with 29 additions and 11 deletions
+12 -6
View File
@@ -373,12 +373,18 @@ AC_TRY_RUN(
[AC_MSG_RESULT([no])]) [AC_MSG_RESULT([no])])
AC_CHECK_FUNC( AC_CHECK_FUNC(
[register_printf_function], [register_printf_specifier],
[AC_DEFINE(HAVE_PRINTF_HOOKS)], dnl new specifier functions with argument length
[ [AC_DEFINE(HAVE_PRINTF_SPECIFIER)],
AC_MSG_NOTICE([printf does not support custom format specifiers!]) [AC_CHECK_FUNC(
vstr=true dnl deprecated function without argument length
] [register_printf_function],
[AC_DEFINE(HAVE_PRINTF_FUNCTION)],
[
AC_MSG_NOTICE([printf does not support custom format specifiers!])
vstr=true
]
)]
) )
if test x$vstr = xtrue; then if test x$vstr = xtrue; then
+15 -4
View File
@@ -75,7 +75,8 @@ static printf_hook_handler_t *printf_hooks[NUM_HANDLERS];
#define SPEC_TO_INDEX(spec) ((int)(spec) - (int)'A') #define SPEC_TO_INDEX(spec) ((int)(spec) - (int)'A')
#define IS_VALID_SPEC(spec) (SPEC_TO_INDEX(spec) > -1 && SPEC_TO_INDEX(spec) < NUM_HANDLERS) #define IS_VALID_SPEC(spec) (SPEC_TO_INDEX(spec) > -1 && SPEC_TO_INDEX(spec) < NUM_HANDLERS)
#if defined(HAVE_PRINTF_HOOKS) && !defined(USE_VSTR) #if !defined(USE_VSTR) && \
(defined(HAVE_PRINTF_FUNCTION) || defined(HAVE_PRINTF_SPECIFIER))
/** /**
* Printf hook print function. This is actually of type "printf_function", * Printf hook print function. This is actually of type "printf_function",
@@ -104,9 +105,13 @@ static int custom_print(FILE *stream, const struct printf_info *info,
/** /**
* Printf hook arginfo function, which is actually of type * Printf hook arginfo function, which is actually of type
* "printf_arginfo_function". * "printf_arginfo_[size_]function".
*/ */
static int custom_arginfo(const struct printf_info *info, size_t n, int *argtypes) static int custom_arginfo(const struct printf_info *info, size_t n, int *argtypes
#ifdef HAVE_PRINTF_SPECIFIER
, int *size
#endif
)
{ {
int i; int i;
printf_hook_handler_t *handler = printf_hooks[SPEC_TO_INDEX(info->spec)]; printf_hook_handler_t *handler = printf_hooks[SPEC_TO_INDEX(info->spec)];
@@ -118,6 +123,7 @@ static int custom_arginfo(const struct printf_info *info, size_t n, int *argtype
argtypes[i] = handler->argtypes[i]; argtypes[i] = handler->argtypes[i];
} }
} }
/* we never set "size", as we have no user defined types */
return handler->numargs; return handler->numargs;
} }
@@ -359,8 +365,13 @@ static void add_handler(private_printf_hook_t *this, char spec,
if (handler->numargs > 0) if (handler->numargs > 0)
{ {
#if defined(HAVE_PRINTF_HOOKS) && !defined(USE_VSTR) #if !defined(USE_VSTR) && \
(defined(HAVE_PRINTF_FUNCTION) || defined(HAVE_PRINTF_SPECIFIER))
# ifdef HAVE_PRINTF_SPECIFIER
register_printf_specifier(spec, custom_print, custom_arginfo);
# else
register_printf_function(spec, custom_print, custom_arginfo); register_printf_function(spec, custom_print, custom_arginfo);
# endif
#else #else
Vstr_conf *conf = get_vstr_conf(); Vstr_conf *conf = get_vstr_conf();
handler->name = malloc(2); handler->name = malloc(2);
+2 -1
View File
@@ -26,7 +26,8 @@ typedef struct printf_hook_t printf_hook_t;
typedef struct printf_hook_spec_t printf_hook_spec_t; typedef struct printf_hook_spec_t printf_hook_spec_t;
typedef enum printf_hook_argtype_t printf_hook_argtype_t; typedef enum printf_hook_argtype_t printf_hook_argtype_t;
#if defined(HAVE_PRINTF_HOOKS) && !defined(USE_VSTR) #if !defined(USE_VSTR) && \
(defined(HAVE_PRINTF_FUNCTION) || defined(HAVE_PRINTF_SPECIFIER))
#include <stdio.h> #include <stdio.h>
#include <printf.h> #include <printf.h>