#ifndef __ERROR_H__
#define __ERROR_H__

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>

#define ERROR_ARG    (-1) /* signifies error with argument */
#define ERROR_ASSERT (-2) /* signifies error with ASSERT */

extern int DEBUG_LEVEL; // defined in charger.c

#ifdef _QNX
#pragma off (check_stack)
int DEBUG(int level, char *str, ...); 
#else
#define DEBUG(level, str, ...) { \
          if (level <= DEBUG_LEVEL) { \
             fprintf (stderr, str, ## __VA_ARGS__); \
          } \
        }
#endif

#ifdef _QNX
int ERROR(char *str, ...); 
#else
#define ERROR(str, ...) { \
           fprintf (stderr, "%s:%d:", __FILE__, __LINE__); \
           fprintf (stderr, str, ## __VA_ARGS__); \
        }
#endif

#define ASSERT(exp) { \
           if (!(exp)) { \
              ERROR ("Assertion failed on line %d in file %s\n", \
                     __LINE__, __FILE__); \
              return ERROR_ASSERT; \
	   } \
        }

#endif /* __ERROR_H__ */
