ee44ee429abc732d8cfcdea44acb0eaf4f760598
[YACASL2.git] / include / cerr.h
1 #ifndef YACASL2_CERR_H_INCLUDED
2 #define YACASL2_CERR_H_INCLUDED
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <assert.h>
8 #include <stdbool.h>
9
10 #ifndef ARRAYSIZE
11 #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
12 #endif
13
14 /* mallocを実行し、メモリを確保できない場合は */
15 /* エラーを出力して終了 */
16 void *malloc_chk(size_t size, char *tag);
17
18 /* callocを実行し、メモリを確保できない場合は */
19 /* エラーを出力して終了 */
20 void *calloc_chk(size_t nmemb, size_t size, char *tag);
21
22 /* malloc_chkを実行してメモリを確保してから、 */
23 /* コピーした文字列を返す */
24 char *strdup_chk(const char *s, char *tag);
25
26 /* エラーの構造体 */
27 typedef struct {
28     int num;        /* エラー番号 */
29     char *msg;      /* エラーメッセージ */
30 } CERR;
31
32 /* 現在のエラー */
33 extern CERR *cerr;
34
35 /* エラーリスト */
36 typedef struct _CERRLIST {
37     struct _CERRLIST *next;
38     CERR *cerr;
39 } CERRLIST;
40
41 extern CERRLIST *cerrlist;
42
43 enum {
44     CERRSTRSIZE = 10,    /* エラーメッセージ中に挿入できる文字列のサイズ */
45     CERRMSGSIZE = 70,    /* エラーメッセージのサイズ */
46 };
47
48 /* エラーの初期化 */
49 void cerr_init();
50
51 /* エラーリストを作成・追加する */
52 bool addcerrlist(int cerrc, CERR cerrv[]);
53
54 /* エラー番号とエラーメッセージを設定 */
55 void setcerr(int num, const char *str);
56
57 /* エラー番号からメッセージを返す */
58 char *getcerrmsg(int num);
59
60 /* エラーを解放する */
61 void freecerr();
62 #endif