1 /*****************************************************************************
2 * RRDtool 1.4.2 Copyright by Tobi Oetiker, 1997-2009
3 *****************************************************************************
4 * rrd_error.c Common Header File
5 *****************************************************************************
8 * Revision 1.4 2003/02/22 21:57:03 oetiker
9 * a patch to avoid a memory leak and a Makefile.am patch to
10 * distribute all required source files -- Peter Stamfest <peter@stamfest.at>
12 * Revision 1.3 2003/02/13 07:05:27 oetiker
13 * Find attached the patch I promised to send to you. Please note that there
14 * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c
15 * and src/rrd_not_thread_safe.c) and the introduction of librrd_th. This
16 * library is identical to librrd, but it contains support code for per-thread
17 * global variables currently used for error information only. This is similar
18 * to how errno per-thread variables are implemented. librrd_th must be linked
19 * alongside of libpthred
21 * There is also a new file "THREADS", holding some documentation.
23 * -- Peter Stamfest <peter@stamfest.at>
25 * Revision 1.2 2002/02/01 20:34:49 oetiker
26 * fixed version number and date/time
28 * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker
31 *************************************************************************** */
40 #define CTX (rrd_get_context())
51 vsnprintf(CTX->rrd_error, sizeof(CTX->rrd_error), fmt, argp);
53 vsprintf(CTX->rrd_error, fmt, argp);
61 return CTX->rrd_error[0] != '\0';
67 CTX->rrd_error[0] = '\0';
73 return CTX->rrd_error;
77 /* PS: Keep this stuff around, maybe we want it again if we use
78 rrd_contexts to really associate them with single RRD files and
79 operations on them... Then a single thread may use more than one
80 context. Using these functions would require to change each and
81 every function containing any of the non _r versions... */
83 rrd_context_t * rrd_ctx,
89 rrd_clear_error_r(rrd_ctx);
92 vsnprintf(rrd_ctx->rrd_error, sizeof(rrd_ctx->rrd_error), fmt, argp);
93 rrd_ctx->rrd_error[sizeof(rrd_ctx->rrd_error) - 1] = '\0';
95 vsprintf(rrd_ctx->rrd_error, fmt, argp);
100 int rrd_test_error_r(
101 rrd_context_t * rrd_ctx)
103 return rrd_ctx->rrd_error[0] != '\0';
106 void rrd_clear_error_r(
107 rrd_context_t * rrd_ctx)
109 rrd_ctx->rrd_error[0] = '\0';
112 char *rrd_get_error_r(
113 rrd_context_t * rrd_ctx)
115 return rrd_ctx->rrd_error;
119 /* PS: Should we move this to some other file? It is not really error
121 rrd_context_t *rrd_new_context(
124 rrd_context_t *rrd_ctx = (rrd_context_t *) malloc(sizeof(rrd_context_t));
130 rrd_ctx->rrd_error[0] = '\0';
131 rrd_ctx->lib_errstr[0] = '\0';
135 void rrd_free_context(
136 rrd_context_t * rrd_ctx)
144 void rrd_globalize_error(
145 rrd_context_t * rrd_ctx)
148 rrd_set_error(rrd_ctx->rrd_error);