]> git.sur5r.net Git - openldap/blobdiff - libraries/liblber/bprint.c
Move schema needed by slapd to core.schema so that only one file
[openldap] / libraries / liblber / bprint.c
index 12862427d489e841a913df8b3f14f8fc206d81ef..ec2949eb71fb06026311384606c9fb9662662a75 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 
 #include "lber-int.h"
 
+/*
+ * We don't just set ber_pvt_err_file to stderr here, because in NT,
+ * stderr is a symbol imported from a DLL. As such, the compiler
+ * doesn't recognize the symbol as having a constant address. Thus
+ * we set ber_pvt_err_file to stderr later, when it first gets
+ * referenced.
+ */
+FILE *ber_pvt_err_file;
+
+/*
+ * ber errno
+ */
+BER_ERRNO_FN ber_int_errno_fn;
+
+int * ber_errno_addr(void)
+{
+       static int ber_int_errno = LBER_ERROR_NONE;
+
+       if( ber_int_errno_fn ) {
+               return (*ber_int_errno_fn)();
+       }
+
+       return &ber_int_errno;
+}
+
 /*
  * Print stuff
  */
 static void
-lber_error_print( char *data )
+ber_error_print( char *data )
 {
+       assert( data != NULL );
+
+       if (!ber_pvt_err_file)
+           ber_pvt_err_file = stderr;
+
+       fputs( data, ber_pvt_err_file );
+
+       /* Print to both streams */
+       if (ber_pvt_err_file != stderr)
+       {
        fputs( data, stderr );
        fflush( stderr );
+       }
+
+       fflush( ber_pvt_err_file );
 }
 
-BER_LOG_PRINT_FN lber_pvt_log_print = lber_error_print;
+BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
 
 /*
  * lber log 
  */
 
-static int lber_log_check( int errlvl, int loglvl )
+static int ber_log_check( int errlvl, int loglvl )
 {
        return errlvl & loglvl ? 1 : 0;
 }
 
-int lber_pvt_log_printf
-#ifdef HAVE_STDARG
-       (int errlvl, int loglvl, char *fmt, ...)
-#else
-       ( va_alist )
-va_dcl
-#endif
+int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
 {
        char buf[ 1024 ];
        va_list ap;
 
-#ifdef HAVE_STDARG
-       va_start( ap, fmt );
-#else
-       int errlvl, loglvl;
-       char *fmt;
-
-       va_start( ap );
+       assert( fmt != NULL );
 
-       errlvl = va_arg( ap, int );
-       loglvl = va_arg( ap, int );
-       fmt = va_arg( ap, char * );
-#endif
-
-       if ( !lber_log_check( errlvl, loglvl )) {
+       if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
        }
 
+       va_start( ap, fmt );
+
 #ifdef HAVE_VSNPRINTF
        buf[sizeof(buf) - 1] = '\0';
        vsnprintf( buf, sizeof(buf)-1, fmt, ap );
@@ -69,22 +93,24 @@ va_dcl
        vsprintf( buf, fmt, ap ); /* hope it's not too long */
 #else
        /* use doprnt() */
-       chokeme = "choke me! I don't have a doprnt manual handy!";
+#error "vsprintf() required."
 #endif
 
        va_end(ap);
 
-       (*lber_pvt_log_print)( buf );
+       (*ber_pvt_log_print)( buf );
        return 1;
 }
 
-static int lber_log_puts(int errlvl, int loglvl, char *buf)
+static int ber_log_puts(int errlvl, int loglvl, char *buf)
 {
-       if ( !lber_log_check( errlvl, loglvl )) {
+       assert( buf != NULL );
+
+       if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
        }
 
-       (*lber_pvt_log_print)( buf );
+       (*ber_pvt_log_print)( buf );
        return 1;
 }
 
@@ -93,9 +119,14 @@ static int lber_log_puts(int errlvl, int loglvl, char *buf)
  */
 
 int
-lber_log_bprint(int errlvl, int loglvl, char *data, int len )
+ber_log_bprint(int errlvl,
+       int loglvl,
+       const char *data,
+       ber_len_t len )
 {
-       if ( !lber_log_check( errlvl, loglvl )) {
+       assert( data != NULL );
+
+       if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
        }
 
@@ -104,7 +135,9 @@ lber_log_bprint(int errlvl, int loglvl, char *data, int len )
 }
 
 void
-ber_bprint(char *data, int len )
+ber_bprint(
+       LDAP_CONST char *data,
+       ber_len_t len )
 {
     static const char  hexdig[] = "0123456789abcdef";
 #define BPLEN  48
@@ -112,11 +145,13 @@ ber_bprint(char *data, int len )
     char       buf[ BPLEN + sizeof("\t%s\n") ];
     int                i = 0;
 
+       assert( data != NULL );
+
     memset( out, 0, BPLEN );
     for ( ;; ) {
        if ( len < 1 ) {
            sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
-               (*lber_pvt_log_print)( buf );
+               (*ber_pvt_log_print)( buf );
            break;
        }
 
@@ -126,8 +161,8 @@ ber_bprint(char *data, int len )
            out[ i+1 ] = *data;
        } else {
 #endif
-           out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
-           out[ i+1 ] = hexdig[ *data & 0x0f ];
+           out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
+           out[ i+1 ] = hexdig[ *data & 0x0fU ];
 #ifndef LDAP_HEX
        }
 #endif
@@ -138,7 +173,7 @@ ber_bprint(char *data, int len )
        if ( i > BPLEN - 2 ) {
                char data[128 + BPLEN];
            sprintf( data, "\t%s\n", out );
-               (*lber_pvt_log_print)(data);
+               (*ber_pvt_log_print)(data);
            memset( out, 0, BPLEN );
            i = 0;
            continue;
@@ -148,9 +183,16 @@ ber_bprint(char *data, int len )
 }
 
 int
-lber_log_dump( int errlvl, int loglvl, BerElement *ber, int inout )
+ber_log_dump(
+       int errlvl,
+       int loglvl,
+       BerElement *ber,
+       int inout )
 {
-       if ( !lber_log_check( errlvl, loglvl )) {
+       assert( ber != NULL );
+       assert( BER_VALID( ber ) );
+
+       if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
        }
 
@@ -159,16 +201,21 @@ lber_log_dump( int errlvl, int loglvl, BerElement *ber, int inout )
 }
 
 void
-ber_dump( BerElement *ber, int inout )
+ber_dump(
+       BerElement *ber,
+       int inout )
 {
        char buf[132];
 
+       assert( ber != NULL );
+       assert( BER_VALID( ber ) );
+
        sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
            (long) ber->ber_buf,
                (long) ber->ber_ptr,
                (long) ber->ber_end );
 
-       (*lber_pvt_log_print)( buf );
+       (*ber_pvt_log_print)( buf );
 
        if ( inout == 1 ) {
                sprintf( buf, "          current len %ld, contents:\n",
@@ -184,9 +231,14 @@ ber_dump( BerElement *ber, int inout )
 }
 
 int
-lber_log_sos_dump( int errlvl, int loglvl, Seqorset *sos )
+ber_log_sos_dump(
+       int errlvl,
+       int loglvl,
+       Seqorset *sos )
 {
-       if ( !lber_log_check( errlvl, loglvl )) {
+       assert( sos != NULL );
+
+       if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
        }
 
@@ -195,26 +247,30 @@ lber_log_sos_dump( int errlvl, int loglvl, Seqorset *sos )
 }
 
 void
-ber_sos_dump( Seqorset *sos )
+ber_sos_dump(
+       Seqorset *sos )
 {
        char buf[132];
 
-       (*lber_pvt_log_print)( "*** sos dump ***\n" );
+       assert( sos != NULL );
 
-       while ( sos != NULLSEQORSET ) {
+       (*ber_pvt_log_print)( "*** sos dump ***\n" );
+
+       while ( sos != NULL ) {
                sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
-                   (long) sos->sos_clen, (long) sos->sos_first, (long) sos->sos_ptr );
-               (*lber_pvt_log_print)( buf );
+                   (long) sos->sos_clen,
+                       (long) sos->sos_first,
+                       (long) sos->sos_ptr );
+               (*ber_pvt_log_print)( buf );
 
                sprintf( buf, "              current len %ld contents:\n",
                    (long) (sos->sos_ptr - sos->sos_first) );
-               (*lber_pvt_log_print)( buf );
+               (*ber_pvt_log_print)( buf );
 
                ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
 
                sos = sos->sos_next;
        }
 
-       (*lber_pvt_log_print)( "*** end dump ***\n" );
+       (*ber_pvt_log_print)( "*** end dump ***\n" );
 }
-