diff options
author | Werner Koch <wk@gnupg.org> | 1999-11-19 16:11:34 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1999-11-19 16:11:34 +0000 |
commit | 5d68aaccefcb3e9c7ff515096a240712962b72c9 (patch) | |
tree | e5181cfd801c41018f720217870ce229198abd13 /src/misc.c | |
parent | 004b4b2bbd984c5efb4ecfa0b1fb3151e3b066bf (diff) | |
download | libgcrypt-5d68aaccefcb3e9c7ff515096a240712962b72c9.tar.gz |
See ChangeLog: Fri Nov 19 17:15:20 CET 1999 Werner Koch
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 123 |
1 files changed, 123 insertions, 0 deletions
@@ -30,6 +30,8 @@ static void (*fatal_error_handler)(void*,int, const char*) = NULL; static void *fatal_error_handler_value = 0; +static void (*log_handler)(void*,int, const char*, va_list) = NULL; +static void *log_handler_value = 0; static const char *(*user_gettext_handler)( const char * ) = NULL; @@ -81,3 +83,124 @@ g10_fatal_error(int rc, const char *text ) abort(); } + +void +gcry_set_log_handler( void (*logf)(void*,int, const char*, va_list ), + void *opaque ) +{ + log_handler = logf; + log_handler_value = opaque; +} + + +/**************** + * This is our log function which prints all log messages to stderr or + * using the function defined with gcry_set_log_handler(). + */ +static void +g10_logv( int level, const char *fmt, va_list arg_ptr ) +{ + if( log_handler ) + log_handler( log_handler_value, level, fmt, arg_ptr ); + else { + switch ( level ) { + case GCRY_LOG_CONT: break; + case GCRY_LOG_INFO: break; + case GCRY_LOG_WARN: break; + case GCRY_LOG_ERROR: break; + case GCRY_LOG_FATAL: fputs("Fatal: ",stderr ); break; + case GCRY_LOG_BUG: fputs("Ohhhh jeeee: ", stderr); break; + case GCRY_LOG_DEBUG: fputs("DBG: ", stderr ); break; + default: fprintf(stderr,"[Unknown log level %d]: ", level ); break; + } + vfprintf(stderr,fmt,arg_ptr) ; + } + + if( level == GCRY_LOG_FATAL ) + exit(2); + else if( level == GCRY_LOG_BUG ) + abort(); +} + +void +g10_log( int level, const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( level, fmt, arg_ptr ); + va_end(arg_ptr); +} + + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +void +g10_bug( const char *file, int line, const char *func ) +{ + g10_log( GCRY_LOG_BUG, + ("... this is a bug (%s:%d:%s)\n"), file, line, func ); + abort(); /* never called, bugs it makes the compiler happy */ +} +#else +void +g10_bug( const char *file, int line ) +{ + g10_log( GCRY_LOG_BUG, + _("you found a bug ... (%s:%d)\n"), file, line); + abort(); /* never called, bugs it makes the compiler happy */ +} +#endif + +void +g10_log_info( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( GCRY_LOG_INFO, fmt, arg_ptr ); + va_end(arg_ptr); +} + +void +g10_log_error( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( GCRY_LOG_ERROR, fmt, arg_ptr ); + va_end(arg_ptr); +} + + +void +g10_log_fatal( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( GCRY_LOG_FATAL, fmt, arg_ptr ); + va_end(arg_ptr); + abort(); /* never called, bugs it makes the compiler happy */ +} + +void +g10_log_bug( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( GCRY_LOG_BUG, fmt, arg_ptr ); + va_end(arg_ptr); + abort(); /* never called, bugs it makes the compiler happy */ +} + +void +g10_log_debug( const char *fmt, ... ) +{ + va_list arg_ptr ; + + va_start( arg_ptr, fmt ) ; + g10_logv( GCRY_LOG_DEBUG, fmt, arg_ptr ); + va_end(arg_ptr); +} + |