File: error.c

package info (click to toggle)
amiwm 0.22pl2-5
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 1,048 kB
  • sloc: ansic: 10,195; perl: 443; makefile: 258; yacc: 245; lex: 215; sh: 211
file content (72 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (2)
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
29
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <string.h>
#include "libami.h"

#ifndef AMIGAOS

static int amiga_errno=0;

#define MIN_ERRNO 103

static const char *syserrmsg[] = {
  "not enough memory available", /* 103 */
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  "bad template", /* 114 */
  "bad number", /* 115 */
  "required argument missing", /* 116 */
  "value after keyword missing", /* 117 */
  "wrong number of arguments", /* 118 */
  NULL,
  "argument line invalid or too long" /* 120 */
};

BOOL Fault(LONG code, UBYTE *header, UBYTE *buffer, LONG len)
{
  amiga_errno=code;
  if(header) {
    int hdlen=strlen((char *)header);
    if(hdlen+2>len)
      return FALSE;
    strcpy((char *)buffer, (char *)header);
    buffer+=hdlen;
    *buffer++=':';
    *buffer++=' ';
    len-=hdlen+2;
  }
  if(code>=MIN_ERRNO && code<MIN_ERRNO+sizeof(syserrmsg)/sizeof(syserrmsg[0])
     && syserrmsg[code-MIN_ERRNO]) {
    if(len<strlen(syserrmsg[code-MIN_ERRNO])+1)
      return FALSE;
    strcpy((char *)buffer, syserrmsg[code-MIN_ERRNO]);
  } else {
    char number[6+4*sizeof(LONG)];
    sprintf(number, "Error %ld", (long)code);
    if(len<strlen(number)+1)
      return FALSE;
    strcpy((char *)buffer, number);
  }
  return TRUE;
}

BOOL PrintFault(LONG code, UBYTE *header)
{
  UBYTE buf[128];
  if(Fault(code, header, buf, sizeof(buf))) {
    fprintf(stderr, "%s\n", (char *)buf);
    return TRUE;
  } else return FALSE;
}

LONG IoErr()
{
  return amiga_errno;
}

LONG SetIoErr(LONG code)
{
  LONG old_errno=amiga_errno;
  amiga_errno=code;
  return old_errno;
}

#endif