char RCS_ID_SANA2PERROR_C[] = "$Id: sana2perror.c,v 1.3 1994/01/12 18:38:06 jasegler Exp jasegler $";
/*
 * sana2perror.c --- print SANA-II error message
 *
 * Author: ppessi <Pekka.Pessi@hut.fi>
 *
 * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
 *                  Helsinki University of Technology, Finland.
 *                  All rights reserved.
 *
 * Created      : Sat Mar 20 02:10:14 1993 ppessi
 * Last modified: Sun Jun 13 03:17:42 1993 ppessi
 */

#ifdef KERNEL
/*
 * Note: This file is to be recompiled with AmiTCP/IP proper
 *       with preprocessor symbol KERNEL defined.
 *       You should NOT link it directly from "net.lib"!
 */
#include <conf.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/syslog.h>
#define fprintf log
#define stderr LOG_ERR
#else
#include <stdio.h>
#endif

#include <devices/sana2.h>
#include <net/sana2errno.h>

void
sana2perror (const char *banner, struct IOSana2Req *ios2)
{
  register WORD err = ios2->ios2_Req.io_Error;
  register ULONG werr = ios2->ios2_WireError;
  const char *errstr;

  if (err >= sana2io_nerr || -err > io_nerr)
    {
      errstr = io_errlist[0];
    }
  else
    {
      if (err < 0)
	/* Negative error codes are common with all IO devices */
	errstr = io_errlist[-err];
      else
	/* Positive error codes are SANA-II specific */
	errstr = sana2io_errlist[err];
    }

  if (werr == 0 || werr >= sana2wire_nerr)
    {
      fprintf (stderr, "%s: %s\n", banner, errstr);
    }
  else
    {
      fprintf (stderr, "%s: %s (%s)\n", banner, errstr, sana2wire_errlist[werr]);
    }
}
