home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ldapsdk.zip / libraries / libldap / print.c < prev    next >
C/C++ Source or Header  |  2000-06-14  |  1KB  |  61 lines

  1. /* $OpenLDAP: pkg/ldap/libraries/libldap/print.c,v 1.5.8.2 2000/06/13 17:57:20 kurt Exp $ */
  2. /*
  3.  * Copyright 1998-2000 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_debug;
  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. }
  61.