view src/generic.c @ 60:97b7706bdda2

Work around bogus 7c.b5 blocks in some messages that have been read. They appear to have attachments, but of some unknown format. Before the message was read, it did not have any attachments. Use autoscan to cleanup our autoconf system. Use autoconf to detect when we need to use our XGetopt files and other header files. More fields, including BCC. Fix missing LE32_CPU byte swapping for FILETIME types.
author Carl Byington <carl@five-ten-sg.com>
date Sat, 16 Feb 2008 12:26:35 -0800
parents f6db1f060a95
children
line wrap: on
line source



#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "generic.h"

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif




void pDIE( char *fmt, ... )
{
    va_list ap;
    va_start( ap, fmt );
        //fprintf( stderr, "Fatal error (will segfault): ");
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    va_end(ap);
        raise( SIGSEGV );
}

void pWARN( char *fmt, ... )
{
    va_list ap;
    va_start( ap, fmt );
        fprintf( stderr, "WARNING: ");
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    va_end(ap);
}

void *F_MALLOC( size_t size )
{
    void *result;

    result = malloc( size );
    ASSERT( NULL != result, "malloc() failure." );

    return result;
}

void *F_REALLOC( void *p, size_t size )
{
    void *result;

    //if( NULL != p ) hexdump((char*)p - 128, 0, 128, 1 );
    if(!p) {
        ASSERT( NULL != ( result = malloc( size ) ), "malloc() failure." );
    }
    else {
        ASSERT( NULL != ( result = realloc( p, size ) ), "realloc() failure." );
    }

    //hexdump((char*)result - 128, 0, 128, 1 );
    fflush(stderr);
    return result;
}



int DEBUG_LEVEL = DB_INFO;

void db_default( char *file, int line, int level, char *fmt, ... )
{
    va_list ap;
    if( level <= DEBUG_LEVEL ) {
        switch( level ) {
            case DB_CRASH:
                fprintf(stderr, "CRASH");
                break;
            case DB_ERR:
                fprintf(stderr, "ERROR");
                break;
            case DB_WARN:
                fprintf(stderr, "WARNING");
                break;
            case DB_INFO:
            case DB_VERB:
                break;
            default:
                fprintf(stderr, "DEBUG(%d)", level );
        }

        if( level <= DB_WARN )
            fprintf(stderr, " (%s:%d)", file, line );

        if( DB_INFO != level && DB_VERB != level )
            fprintf(stderr, ": ");

        va_start( ap, fmt );
        vfprintf(stderr, fmt, ap );
        fprintf(stderr, "\n" );
        va_end( ap );
    }
}

void (*dbfunc)(char *file, int line, int level, char *fmt, ...) = &db_default;