Xively C library
Dependents: xively-jumpstart-demo
This is Xively C library, the code lives on GitHub.
See our example program and the tutorial, documentation can bee found here.
src/libxively/xi_printf.c@0:53753690a8bf, 2013-05-13 (annotated)
- Committer:
- xively
- Date:
- Mon May 13 19:28:22 2013 +0000
- Revision:
- 0:53753690a8bf
libxively v0.1.1-rc0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xively | 0:53753690a8bf | 1 | // Copyright (c) 2003-2013, LogMeIn, Inc. All rights reserved. |
xively | 0:53753690a8bf | 2 | // This is part of Xively C library, it is under the BSD 3-Clause license. |
xively | 0:53753690a8bf | 3 | |
xively | 0:53753690a8bf | 4 | /** |
xively | 0:53753690a8bf | 5 | * \file xi_printf.c |
xively | 0:53753690a8bf | 6 | * \author Olgierd Humenczuk |
xively | 0:53753690a8bf | 7 | * \brief Our custom `printf()` hook [see xi_printf.h] |
xively | 0:53753690a8bf | 8 | */ |
xively | 0:53753690a8bf | 9 | |
xively | 0:53753690a8bf | 10 | #include <stdarg.h> |
xively | 0:53753690a8bf | 11 | #include <stdio.h> |
xively | 0:53753690a8bf | 12 | |
xively | 0:53753690a8bf | 13 | #include "xi_printf.h" |
xively | 0:53753690a8bf | 14 | #include "xi_consts.h" |
xively | 0:53753690a8bf | 15 | |
xively | 0:53753690a8bf | 16 | #ifdef __cplusplus |
xively | 0:53753690a8bf | 17 | extern "C" { |
xively | 0:53753690a8bf | 18 | #endif |
xively | 0:53753690a8bf | 19 | |
xively | 0:53753690a8bf | 20 | user_print_t USER_PRINT = 0; |
xively | 0:53753690a8bf | 21 | |
xively | 0:53753690a8bf | 22 | int xi_printf( const char *fmt, ... ) |
xively | 0:53753690a8bf | 23 | { |
xively | 0:53753690a8bf | 24 | char buffer[ XI_PRINTF_BUFFER_SIZE ]; |
xively | 0:53753690a8bf | 25 | int n = 0; |
xively | 0:53753690a8bf | 26 | |
xively | 0:53753690a8bf | 27 | va_list ap; |
xively | 0:53753690a8bf | 28 | va_start( ap, fmt ); |
xively | 0:53753690a8bf | 29 | vsnprintf( buffer, XI_PRINTF_BUFFER_SIZE, fmt, ap ); |
xively | 0:53753690a8bf | 30 | va_end( ap ); |
xively | 0:53753690a8bf | 31 | |
xively | 0:53753690a8bf | 32 | |
xively | 0:53753690a8bf | 33 | if( USER_PRINT ) |
xively | 0:53753690a8bf | 34 | { |
xively | 0:53753690a8bf | 35 | USER_PRINT( buffer ); |
xively | 0:53753690a8bf | 36 | } |
xively | 0:53753690a8bf | 37 | else |
xively | 0:53753690a8bf | 38 | { |
xively | 0:53753690a8bf | 39 | printf( "%s", buffer ); |
xively | 0:53753690a8bf | 40 | } |
xively | 0:53753690a8bf | 41 | |
xively | 0:53753690a8bf | 42 | return n; |
xively | 0:53753690a8bf | 43 | } |
xively | 0:53753690a8bf | 44 | |
xively | 0:53753690a8bf | 45 | #ifdef __cplusplus |
xively | 0:53753690a8bf | 46 | } |
xively | 0:53753690a8bf | 47 | #endif |