1/* $NetBSD: print.c,v 1.1.1.3 2010/12/12 15:21:34 adam Exp $ */ 2 3/* OpenLDAP: pkg/ldap/libraries/libldap/print.c,v 1.16.2.5 2010/04/13 20:22:59 kurt Exp */ 4/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1998-2010 The OpenLDAP Foundation. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted only as authorized by the OpenLDAP 11 * Public License. 12 * 13 * A copy of this license is available in the file LICENSE in the 14 * top-level directory of the distribution or, alternatively, at 15 * <http://www.OpenLDAP.org/license.html>. 16 */ 17 18#include "portable.h" 19 20#include <stdio.h> 21 22#include <ac/ctype.h> 23#include <ac/stdarg.h> 24#include <ac/string.h> 25#include <ac/time.h> 26 27#include "ldap-int.h" 28 29/* 30 * ldap log 31 */ 32 33static int ldap_log_check( LDAP *ld, int loglvl ) 34{ 35 int errlvl; 36 37 if(ld == NULL) { 38 errlvl = ldap_debug; 39 } else { 40 errlvl = ld->ld_debug; 41 } 42 43 return errlvl & loglvl ? 1 : 0; 44} 45 46int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... ) 47{ 48 char buf[ 1024 ]; 49 va_list ap; 50 51 if ( !ldap_log_check( ld, loglvl )) { 52 return 0; 53 } 54 55 va_start( ap, fmt ); 56 57 buf[sizeof(buf) - 1] = '\0'; 58 vsnprintf( buf, sizeof(buf)-1, fmt, ap ); 59 60 va_end(ap); 61 62 (*ber_pvt_log_print)( buf ); 63 return 1; 64} 65