/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* error.c: ANSI draft (X3J11 May 86) code (various error routines) */
/* Copyright (C) A.C. Norman and A. Mycroft */
/* version 0.01b */

#include "hostsys.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <signal.h>
#include <assert.h>  /* for __assert() */
#include <string.h>  /* for strerror */
#include <errno.h>
#include "kernel.h"

extern int _fprintf_lf(FILE *fp, const char *fmt, ...);
extern int _sprintf_lf(char *buff, const char *fmt, ...);

void _sysdie(const char *s)
{
    char v[200];
    char *cs, *ct;

    cs = v;
    ct = _kernel_getmessage("*** fatal error in run time system: ", "C33");
    while ((*cs++ = *ct++) >= ' ');
    cs--;
    ct = (char *)s;
    while ((*cs++ = *ct++) >= ' ');
    _sys_msg(v);
    exit(1);
}

/* from <assert.h> */
void __assert(char *expr, char *file, int line)
{
    _fprintf_lf(stderr,
                _kernel_getmessage("*** assertion failed: %s, file %s, line %d", "C34"),
                expr, file, line);
    fputc('\n', stderr);
    abort();
}

extern char *_hostos_error_string(int no, char *buf) {
    buf = buf; /* unused */
    if (no == -1) {
        _kernel_oserror *e = _kernel_last_oserror();
        return (e == NULL) ? _kernel_getmessage("unspecified error", "C69") : e->errmess;
    } else {
        return _kernel_getmessage("unknown error", "C70");
    }
}

/* end of error.c */