1 /*****************************************************************************
2 * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002
3 *****************************************************************************
4 * rrd_error.c Common Header File
5 *****************************************************************************
8 * Revision 1.3 2003/02/13 07:05:27 oetiker
9 * Find attached the patch I promised to send to you. Please note that there
10 * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c
11 * and src/rrd_not_thread_safe.c) and the introduction of librrd_th. This
12 * library is identical to librrd, but it contains support code for per-thread
13 * global variables currently used for error information only. This is similar
14 * to how errno per-thread variables are implemented. librrd_th must be linked
15 * alongside of libpthred
17 * There is also a new file "THREADS", holding some documentation.
19 * -- Peter Stamfest <peter@stamfest.at>
21 * Revision 1.2 2002/02/01 20:34:49 oetiker
22 * fixed version number and date/time
24 * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker
27 *************************************************************************** */
34 #define CTX (rrd_get_context())
37 rrd_set_error(char *fmt, ...)
43 vsnprintf(CTX->rrd_error, CTX->len, fmt, argp);
45 vsprintf(CTX->rrd_error, fmt, argp);
51 rrd_test_error(void) {
52 return CTX->rrd_error[0] != '\0';
56 rrd_clear_error(void){
57 CTX->rrd_error[0] = '\0';
62 return CTX->rrd_error;
66 /* PS: Keep this stuff around, maybe we want it again if we use
67 rrd_contexts to really associate them with single RRD files and
68 operations on them... Then a single thread may use more than one
69 context. Using these functions would require to change each and
70 every function containing any of the non _r versions... */
72 rrd_set_error_r(struct rrd_context *rrd_ctx, char *fmt, ...)
75 rrd_clear_error_r(rrd_ctx);
78 vsnprintf((char *)rrd_ctx->rrd_error, rrd_ctx->len, fmt, argp);
80 vsprintf((char *)rrd_ctx->rrd_error, fmt, argp);
86 rrd_test_error_r(struct rrd_context *rrd_ctx) {
87 return rrd_ctx->rrd_error[0] != '\0';
91 rrd_clear_error_r(struct rrd_context *rrd_ctx) {
92 rrd_ctx->rrd_error[0] = '\0';
96 rrd_get_error_r(struct rrd_context *rrd_ctx) {
97 return (char *)rrd_ctx->rrd_error;
101 /* PS: Should we move this to some other file? It is not really error
104 rrd_new_context(void) {
105 struct rrd_context *rrd_ctx =
106 (struct rrd_context *) malloc(sizeof(struct rrd_context));
110 rrd_ctx->rrd_error = malloc(MAXLEN);
111 rrd_ctx->lib_errstr = malloc(ERRBUFLEN);
112 if (rrd_ctx->rrd_error && rrd_ctx->lib_errstr) {
113 *rrd_ctx->rrd_error = 0;
114 *rrd_ctx->lib_errstr = 0;
115 rrd_ctx->len = MAXLEN;
116 rrd_ctx->errlen = ERRBUFLEN;
119 if (rrd_ctx->rrd_error) free(rrd_ctx->rrd_error);
120 if (rrd_ctx->lib_errstr) free(rrd_ctx->lib_errstr);
127 rrd_free_context(struct rrd_context *rrd_ctx) {
129 if (rrd_ctx->rrd_error) free(rrd_ctx->rrd_error);
135 void rrd_globalize_error(struct rrd_context *rrd_ctx) {
137 rrd_set_error(rrd_ctx->rrd_error);