/******************************************************************************/
/*                       Copyright 2001 Broadcom Corporation                  */
/*                                                                            */
/* This material is the confidential trade secret and proprietary information */
/* of Broadcom Corp.  It may not be reproduced, used, sold or transferred to  */
/* any third party without the prior written consent of Broadcom Corp.        */
/* All rights reserved.                                                       */
/******************************************************************************/
/*   FileName        : bcm_errorHandler.c                                     */
/*   Purpose         : error handler                                          */
/*   Limitations     : None                                                   */
/*   Author          : Emmanuel Hanssens                                      */
/*   Creation Date   : 14-Sep-2001                                            */
/*   History         : Compiled by CVS                                        */
/******************************************************************************/
/*   $Id: bcm_errorHandler.c,v 1.7 2004/09/27 15:33:10 hanssens Exp $  */
/******************************************************************************/

#include "bcm_userdef.h"
#include "bcm_errorHandler.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#if defined (_WIN32) && (PLATFORM != CYGWIN)
# define snprintf _snprintf
#endif

/* Soft error handling: print error and return */
int errorHandler(const char *fileName,     /* file name where error was seen */
                 const int   line,         /* line in file */
                 int         errorType,    /* type of detected error */
                 const char *fmt,          /* format string (like printf) */
                 ...)
{
#ifndef NO_STDERR_PRINT
  char format[MAX_ERROR_LEN];

  va_list args;
  
  snprintf(format, MAX_ERROR_LEN, "\nERROR in %s,%d: %s.\n",
           fileName, line, fmt);

  va_start(args, fmt);
  vfprintf(stderr, format, args);
  va_end(args);

#else
  
  BCM_UNUSED_PARAMETER(fmt);
  BCM_UNUSED_PARAMETER(fileName);
  BCM_UNUSED_PARAMETER(line);

#endif

  return errorType;
}


#ifndef CUSTOM_FATAL_ERROR

/* Fatal error handling: print error and exit */
void fatalError(const char *fileName,     /* file name where error was seen */
                const int   line,         /* line in file */
                const char *fmt,          /* format string (like printf) */
                ...)
{
# ifndef NO_STDERR_PRINT
  char format[MAX_ERROR_LEN];

  va_list args;
  
  snprintf(format, MAX_ERROR_LEN, "\nFatal ERROR in %s,%d: %s.\nExiting\n",
           fileName, line, fmt);

  va_start(args, fmt);
  vfprintf(stderr, format, args);
  va_end(args);

# else

  BCM_UNUSED_PARAMETER(fmt);
  BCM_UNUSED_PARAMETER(fileName);
  BCM_UNUSED_PARAMETER(line);

# endif

  //exit(1);
}

#endif
