Modify rtems_bsd_set_vprintf_handler()

Return previous vprintf()-handler in rtems_bsd_set_vprintf_handler().
This commit is contained in:
Sebastian Huber 2016-06-28 08:35:06 +02:00
parent 6ff1baa08d
commit 520ab224ca
3 changed files with 21 additions and 8 deletions

View File

@ -206,15 +206,22 @@ int rtems_bsd_bus_root_resume(void);
*/ */
int rtems_bsd_bus_root_detach(void); int rtems_bsd_bus_root_detach(void);
/**
* @brief The output back-end for logging functions.
*/
typedef int (*rtems_bsd_vprintf_handler)(int, const char *, va_list);
/** /**
* @brief Sets the output back-end for logging functions. * @brief Sets the output back-end for logging functions.
* *
* @param new_vprintf_handler The new output back-end for logging functions. * @param new_handler The new output back-end for logging functions.
*
* @return The previous handler.
* *
* @see rtems_bsd_vprintf(). * @see rtems_bsd_vprintf().
*/ */
void rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler) rtems_bsd_vprintf_handler rtems_bsd_set_vprintf_handler(
(int, const char *, va_list)); rtems_bsd_vprintf_handler new_handler);
/** /**
* @brief Output back-end for logging functions. * @brief Output back-end for logging functions.

View File

@ -103,12 +103,16 @@ default_vprintf_handler(int level, const char *fmt, va_list ap)
static int (*vprintf_handler)(int, const char *, va_list) = static int (*vprintf_handler)(int, const char *, va_list) =
default_vprintf_handler; default_vprintf_handler;
void rtems_bsd_vprintf_handler
rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler) rtems_bsd_set_vprintf_handler(rtems_bsd_vprintf_handler new_handler)
(int, const char *, va_list))
{ {
rtems_bsd_vprintf_handler old_handler;
vprintf_handler = new_vprintf_handler; VPRINTF_LOCK();
old_handler = vprintf_handler;
vprintf_handler = new_handler;
VPRINTF_UNLOCK();
return (old_handler);
} }
int int

View File

@ -32,8 +32,8 @@
#include <machine/rtems-bsd-kernel-space.h> #include <machine/rtems-bsd-kernel-space.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/syslog.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <syslog.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
@ -42,6 +42,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <rtems/bsd/bsd.h>
#define TEST_NAME "LIBBSD LOG 1" #define TEST_NAME "LIBBSD LOG 1"
typedef struct { typedef struct {