prepare for the release of rrdtool-1.2.17
[rrdtool.git] / src / rrd_not_thread_safe.c
1 /*****************************************************************************
2  * RRDtool 1.2.17  Copyright by Tobi Oetiker, 1997-2006
3  * This file:     Copyright 2003 Peter Stamfest <peter@stamfest.at> 
4  *                             & Tobias Oetiker
5  * Distributed under the GPL
6  *****************************************************************************
7  * rrd_not_thread_safe.c   Contains routines used when thread safety is not
8  *                         an issue
9  *****************************************************************************
10  * $Id$
11  *************************************************************************** */
12 #include "rrd.h"
13 #include "rrd_tool.h"
14 #define MAXLEN 4096
15 #define ERRBUFLEN 256
16
17 static char rrd_error[MAXLEN+10];
18 static char rrd_liberror[ERRBUFLEN+10];
19 static int  rrd_context_init = 0;
20 /* The global context is very useful in the transition period to even
21    more thread-safe stuff, it can be used whereever we need a context
22    and do not need to worry about concurrency. */
23 static struct rrd_context global_ctx = {
24     MAXLEN,
25     ERRBUFLEN,
26     rrd_error, 
27     rrd_liberror
28 };
29 /* #include <stdarg.h> */
30
31 struct rrd_context *rrd_get_context(void) {
32     if (! rrd_context_init ){
33         rrd_context_init = 1;
34         global_ctx.rrd_error[0]='\0';
35         global_ctx.lib_errstr[0]='\0';
36     }
37     return &global_ctx;
38 }
39
40 /* how ugly that is!!! - make sure strerror is what it should be. It
41    might be redefined to help in keeping other modules thread safe by
42    silently turning misplaced strerror into rrd_strerror, but here
43    this turns recursive! */
44 #undef strerror
45 const char *rrd_strerror(int err) {
46     return strerror(err);
47 }