error 1.95 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* 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>
Kevin Bracey's avatar
Kevin Bracey committed
29
#include "kernel.h"
Neil Turton's avatar
Neil Turton committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

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();
}

Kevin Bracey's avatar
Kevin Bracey committed
59 60 61 62 63 64 65
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");
Neil Turton's avatar
Neil Turton committed
66 67 68 69
    }
}

/* end of error.c */