1/*
2 * << Haru Free PDF Library >> -- hpdf_error.c
3 *
4 * URL: http://libharu.org
5 *
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8 *
9 * Permission to use, copy, modify, distribute and sell this software
10 * and its documentation for any purpose is hereby granted without fee,
11 * provided that the above copyright notice appear in all copies and
12 * that both that copyright notice and this permission notice appear
13 * in supporting documentation.
14 * It is provided "as is" without express or implied warranty.
15 *
16 */
17
18#include "hpdf_conf.h"
19#include "hpdf_utils.h"
20#include "hpdf_error.h"
21#include "hpdf_consts.h"
22#include "hpdf.h"
23
24#ifndef HPDF_STDCALL
25#ifdef HPDF_DLL_MAKE
26#define HPDF_STDCALL __stdcall
27#else
28#ifdef HPDF_DLL
29#define HPDF_STDCALL __stdcall
30#else
31#define HPDF_STDCALL
32#endif
33#endif
34#endif
35
36void
37HPDF_CopyError (HPDF_Error dst,
38 HPDF_Error src);
39
40
41void
42HPDF_Error_Init (HPDF_Error error,
43 void *user_data)
44{
45 HPDF_MemSet(error, 0, sizeof(HPDF_Error_Rec));
46
47 error->user_data = user_data;
48}
49
50HPDF_STATUS
51HPDF_Error_GetCode (HPDF_Error error)
52{
53 return error->error_no;
54}
55
56HPDF_STATUS
57HPDF_Error_GetDetailCode (HPDF_Error error)
58{
59 return error->detail_no;
60}
61
62void
63HPDF_CopyError (HPDF_Error dst,
64 HPDF_Error src)
65{
66 dst->error_no = src->error_no;
67 dst->detail_no = src->detail_no;
68 dst->error_fn = src->error_fn;
69 dst->user_data = src->user_data;
70}
71
72HPDF_STATUS
73HPDF_SetError (HPDF_Error error,
74 HPDF_STATUS error_no,
75 HPDF_STATUS detail_no)
76{
77 HPDF_PTRACE((" HPDF_SetError: error_no=0x%04X "
78 "detail_no=0x%04X\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no));
79
80 error->error_no = error_no;
81 error->detail_no = detail_no;
82
83 return error_no;
84}
85
86
87HPDF_EXPORT(HPDF_STATUS)
88HPDF_CheckError (HPDF_Error error)
89{
90 HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n",
91 (HPDF_UINT)error->error_no, (HPDF_UINT)error->detail_no));
92
93 if (error->error_no != HPDF_OK && error->error_fn)
94 error->error_fn (error->error_no, error->detail_no, error->user_data);
95
96 return error->error_no;
97}
98
99
100HPDF_STATUS
101HPDF_RaiseError (HPDF_Error error,
102 HPDF_STATUS error_no,
103 HPDF_STATUS detail_no)
104{
105 HPDF_SetError (error, error_no, detail_no);
106
107 return HPDF_CheckError (error);
108}
109
110
111void
112HPDF_Error_Reset (HPDF_Error error)
113{
114 error->error_no = HPDF_NOERROR;
115 error->detail_no = HPDF_NOERROR;
116}
117
118
119