1 /*****************************************************************************
2 * RRDtool 1.2.14 Copyright by Tobi Oetiker, 1997-2006
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 *************************************************************************** */
38 #define CTX (rrd_get_context())
41 rrd_set_error(char *fmt, ...)
47 vsnprintf(CTX->rrd_error, CTX->len, fmt, argp);
49 vsprintf(CTX->rrd_error, fmt, argp);
55 rrd_test_error(void) {
56 return CTX->rrd_error[0] != '\0';
60 rrd_clear_error(void){
61 CTX->rrd_error[0] = '\0';
66 return CTX->rrd_error;
70 /* PS: Keep this stuff around, maybe we want it again if we use
71 rrd_contexts to really associate them with single RRD files and
72 operations on them... Then a single thread may use more than one
73 context. Using these functions would require to change each and
74 every function containing any of the non _r versions... */
76 rrd_set_error_r(struct rrd_context *rrd_ctx, char *fmt, ...)
79 rrd_clear_error_r(rrd_ctx);
82 vsnprintf((char *)rrd_ctx->rrd_error, rrd_ctx->len, fmt, argp);
84 vsprintf((char *)rrd_ctx->rrd_error, fmt, argp);
90 rrd_test_error_r(struct rrd_context *rrd_ctx) {
91 return rrd_ctx->rrd_error[0] != '\0';
95 rrd_clear_error_r(struct rrd_context *rrd_ctx) {
96 rrd_ctx->rrd_error[0] = '\0';
100 rrd_get_error_r(struct rrd_context *rrd_ctx) {
101 return (char *)rrd_ctx->rrd_error;
105 /* PS: Should we move this to some other file? It is not really error
108 rrd_new_context(void) {
109 struct rrd_context *rrd_ctx =
110 (struct rrd_context *) malloc(sizeof(struct rrd_context));
114 rrd_ctx->rrd_error = malloc(MAXLEN+10);
115 rrd_ctx->lib_errstr = malloc(ERRBUFLEN+10);
116 if (rrd_ctx->rrd_error && rrd_ctx->lib_errstr) {
117 *rrd_ctx->rrd_error = 0;
118 *rrd_ctx->lib_errstr = 0;
119 rrd_ctx->len = MAXLEN;
120 rrd_ctx->errlen = ERRBUFLEN;
123 if (rrd_ctx->rrd_error) free(rrd_ctx->rrd_error);
124 if (rrd_ctx->lib_errstr) free(rrd_ctx->lib_errstr);
131 rrd_free_context(struct rrd_context *rrd_ctx) {
133 if (rrd_ctx->rrd_error) free(rrd_ctx->rrd_error);
134 if (rrd_ctx->lib_errstr) free(rrd_ctx->lib_errstr);
140 void rrd_globalize_error(struct rrd_context *rrd_ctx) {
142 rrd_set_error(rrd_ctx->rrd_error);