No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / liblber / debug.c
blob59ccc6c5d8b15e9133a56a17569404fe7c3292a6
1 /* $OpenLDAP: pkg/ldap/libraries/liblber/debug.c,v 1.21.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 #include "portable.h"
18 #include <stdio.h>
20 #include <ac/stdarg.h>
21 #include <ac/stdlib.h>
22 #include <ac/string.h>
23 #include <ac/time.h>
24 #include <ac/ctype.h>
26 #ifdef LDAP_SYSLOG
27 #include <ac/syslog.h>
28 #endif
30 #include "ldap_log.h"
31 #include "ldap_defaults.h"
32 #include "lber.h"
33 #include "ldap_pvt.h"
35 static FILE *log_file = NULL;
37 int lutil_debug_file( FILE *file )
39 log_file = file;
40 ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
42 return 0;
45 void (lutil_debug)( int debug, int level, const char *fmt, ... )
47 char buffer[4096];
48 va_list vl;
50 if ( !(level & debug ) ) return;
52 #ifdef HAVE_WINSOCK
53 if( log_file == NULL ) {
54 log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
56 if ( log_file == NULL ) {
57 log_file = fopen( "openldap.log", "w" );
58 if ( log_file == NULL ) return;
61 ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, log_file );
63 #endif
65 va_start( vl, fmt );
66 vsnprintf( buffer, sizeof(buffer), fmt, vl );
67 buffer[sizeof(buffer)-1] = '\0';
68 if( log_file != NULL ) {
69 fputs( buffer, log_file );
70 fflush( log_file );
72 fputs( buffer, stderr );
73 va_end( vl );
76 #if defined(HAVE_EBCDIC) && defined(LDAP_SYSLOG)
77 #undef syslog
78 void eb_syslog( int pri, const char *fmt, ... )
80 char buffer[4096];
81 va_list vl;
83 va_start( vl, fmt );
84 vsnprintf( buffer, sizeof(buffer), fmt, vl );
85 buffer[sizeof(buffer)-1] = '\0';
87 /* The syslog function appears to only work with pure EBCDIC */
88 __atoe(buffer);
89 #pragma convlit(suspend)
90 syslog( pri, "%s", buffer );
91 #pragma convlit(resume)
92 va_end( vl );
94 #endif