X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=log.c;h=b5402f8bb8e21b81961be9f16b5ef9ebb3623827;hp=73c1fdde89bca9acb797fda11500f27e913e1405;hb=2842721f189c5338d268a6e70002936289ae6069;hpb=367843620d039ad183bc4d7c33d91c316d717621 diff --git a/log.c b/log.c index 73c1fdd..b5402f8 100644 --- a/log.c +++ b/log.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ #include @@ -23,6 +22,7 @@ #include "libsigrokdecode.h" #include #include +#include /** * @file @@ -129,6 +129,28 @@ SRD_API int srd_log_callback_set(srd_log_callback cb, void *cb_data) return SRD_OK; } +/** + * Get the libsigrokdecode log callback routine and callback data. + * + * @param[out] cb Pointer to a function pointer to receive the log callback + * function. Optional, can be NULL. + * @param[out] cb_data Pointer to a void pointer to receive the log callback's + * additional arguments. Optional, can be NULL. + * + * @return SRD_OK upon success. + * + * @since 0.6.0 + */ +SRD_API int srd_log_callback_get(srd_log_callback *cb, void **cb_data) +{ + if (cb) + *cb = srd_log_cb; + if (cb_data) + *cb_data = srd_log_cb_data; + + return SRD_OK; +} + /** * Set the libsigrokdecode log callback to the default built-in one. * @@ -153,20 +175,19 @@ SRD_API int srd_log_callback_set_default(void) static int srd_logv(void *cb_data, int loglevel, const char *format, va_list args) { - int ret; - /* This specific log callback doesn't need the void pointer data. */ (void)cb_data; - /* Only output messages of at least the selected loglevel(s). */ - if (loglevel > cur_loglevel) - return SRD_OK; + (void)loglevel; - fputs("srd: ", stderr); - ret = vfprintf(stderr, format, args); - fprintf(stderr, "\n"); + if (fputs("srd: ", stderr) < 0 + || g_vfprintf(stderr, format, args) < 0 + || putc('\n', stderr) < 0) + return SRD_ERR; - return ret; + fflush(stderr); + + return SRD_OK; } /** @private */ @@ -175,6 +196,10 @@ SRD_PRIV int srd_log(int loglevel, const char *format, ...) int ret; va_list args; + /* Only output messages of at least the selected loglevel(s). */ + if (loglevel > cur_loglevel) + return SRD_OK; + va_start(args, format); ret = srd_log_cb(srd_log_cb_data, loglevel, format, args); va_end(args);