-
Notifications
You must be signed in to change notification settings - Fork 12
/
error.c
52 lines (47 loc) · 1.36 KB
/
error.c
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
/*=======================================================================
solunar
error.c
Definition of Error object
(c)2005-2012 Kevin Boone
=======================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
typedef struct _ErrorPriv
{
char *str;
} ErrorPriv;
/*=======================================================================
Error_free
=======================================================================*/
void Error_free (Error *self)
{
if (!self) return;
if (self->priv)
{
if (self->priv->str) free (self->priv->str);
free (self->priv);
}
free (self);
}
/*=======================================================================
Error_new
=======================================================================*/
Error *Error_new (const char *message)
{
Error *self = (Error *) malloc (sizeof (Error));
self->priv = (ErrorPriv *) malloc (sizeof (ErrorPriv));
self->priv->str = strdup (message);
return self;
}
/*=======================================================================
Error_get_message
=======================================================================*/
const char *Error_get_message (Error *self)
{
if (!self) return "";
if (!self->priv) return "";
if (!self->priv->str) return "";
return self->priv->str;
}