~ubuntu-branches/ubuntu/trusty/scim-bridge/trusty

« back to all changes in this revision

Viewing changes to common/scim-bridge-exception.c

  • Committer: Bazaar Package Importer
  • Author(s): Hou ZhengPeng
  • Date: 2006-04-02 18:07:30 UTC
  • Revision ID: james.westby@ubuntu.com-20060402180730-x4zlfe8odh4yzcld
Tags: upstream-0.1.3
ImportĀ upstreamĀ versionĀ 0.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <assert.h>
 
2
#include <malloc.h>
 
3
#include <string.h>
 
4
 
 
5
#include "scim-bridge-exception.h"
 
6
 
 
7
static const char EMPTY_MESSAGE[] = "\0";
 
8
 
 
9
void scim_bridge_exception_initialize (ScimBridgeException *except)
 
10
{
 
11
    memset (except, 0, sizeof (ScimBridgeException));
 
12
}
 
13
 
 
14
 
 
15
void scim_bridge_exception_finalize (ScimBridgeException *except)
 
16
{
 
17
    if (except->message != NULL) {
 
18
        free (except->message);
 
19
        except->message = NULL;
 
20
    }
 
21
}
 
22
 
 
23
 
 
24
void scim_bridge_exception_copy (ScimBridgeException *dest, const ScimBridgeException *except)
 
25
{
 
26
    scim_bridge_exception_set_message (dest, except->message);
 
27
    scim_bridge_exception_set_errno (dest, except->err_no);
 
28
}
 
29
 
 
30
 
 
31
void scim_bridge_exception_set_message (ScimBridgeException *except, const char *new_message)
 
32
{
 
33
    if (new_message != NULL) {
 
34
        const size_t str_len = strlen (new_message);
 
35
        except->message = malloc (sizeof (char) * (str_len + 1));
 
36
        strcpy (except->message, new_message);
 
37
    } else {
 
38
        free (except->message);
 
39
        except->message = NULL;
 
40
    }
 
41
}
 
42
 
 
43
 
 
44
const char *scim_bridge_exception_get_message (const ScimBridgeException *except)
 
45
{
 
46
    if (except->message) {
 
47
        return except->message;
 
48
    } else {
 
49
        return EMPTY_MESSAGE;
 
50
    }
 
51
}
 
52
 
 
53
 
 
54
void scim_bridge_exception_set_errno (ScimBridgeException *except, const int new_errno)
 
55
{
 
56
    except->err_no = new_errno;
 
57
}
 
58
 
 
59
 
 
60
int scim_bridge_exception_get_errno (const ScimBridgeException *except)
 
61
{
 
62
    return except->err_no;
 
63
}
 
64
 
 
65
 
 
66
const char *scim_bridge_exception_get_strerror (const ScimBridgeException *except)
 
67
{
 
68
    return strerror (except->err_no);
 
69
}