/***************************************************************

   errchk

      These functions are to simplify the handling of
      common fatal errors.  The 'exit' function is used,
      so we are relying on the system to close files,
      etc.

      Header: ioserv.h
      Library: ioserv_x.h
*/

#include "common.h"   /* exit() */
#include "ioserv.h"   /* report_msg() */

#if PROTOTYPE_ALLOWED
FILE *check_fopen(char *fn, char *mode)
#else
FILE *check_fopen(fn, mode)
   char *fn, *mode;
#endif
{
   FILE *fp;
   char buff[255];

   if ( (fp = fopen(fn, mode)) == NULL)
   {
      sprintf(buff, "\n%%%% ERROR: File %s could not be opened.\n\n", fn);
      report_msg(buff);
      exit(-1);
   }
   return(fp);
}

#if PROTOTYPE_ALLOWED
void check_error(int test, char *message )
#else
void check_error( test, message )
   int test;
   char *message;
#endif
{
   char buff[255];

   if (test)
   {
      sprintf(buff, "\n%%%% ERROR: %d, %s\n", test, message);
      report_msg(buff);
      exit(-1);
   }
   return;
}

