]> git.sur5r.net Git - openldap/blob - libraries/libldap/print.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / libraries / libldap / print.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/ctype.h>
12 #include <ac/stdarg.h>
13 #include <ac/string.h>
14 #include <ac/time.h>
15
16 #include "ldap-int.h"
17
18 /*
19  * ldap log 
20  */
21
22 static int ldap_log_check( LDAP *ld, int loglvl )
23 {
24         int errlvl;
25
26         if(ld == NULL) {
27                 errlvl = ldap_debug;
28         } else {
29                 errlvl = ld->ld_errno;
30         }
31
32         return errlvl & loglvl ? 1 : 0;
33 }
34
35 int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... )
36 {
37         char buf[ 1024 ];
38         va_list ap;
39
40         if ( !ldap_log_check( ld, loglvl )) {
41                 return 0;
42         }
43
44         va_start( ap, fmt );
45
46 #ifdef HAVE_VSNPRINTF
47         buf[sizeof(buf) - 1] = '\0';
48         vsnprintf( buf, sizeof(buf)-1, fmt, ap );
49 #elif HAVE_VSPRINTF
50         vsprintf( buf, fmt, ap ); /* hope it's not too long */
51 #else
52         /* use doprnt() */
53         chokeme = "choke me! I don't have a doprnt manual handy!";
54 #endif
55
56         va_end(ap);
57
58         (*ber_pvt_log_print)( buf );
59         return 1;
60 }