1 /*****************************************************************************
2 * RRDtool 1.3rc4 Copyright by Tobi Oetiker, 1997-2008
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: rrd_not_thread_safe.c 1366 2008-05-18 13:06:44Z oetiker $
11 *************************************************************************** */
12 #include "rrd.h"
13 #include "rrd_tool.h"
14 #define MAXLEN 4096
15 #define ERRBUFLEN 256
17 static char rrd_error[MAXLEN + 10];
18 static char rrd_liberror[ERRBUFLEN + 10];
19 static int rrd_context_init = 0;
21 /* The global context is very useful in the transition period to even
22 more thread-safe stuff, it can be used whereever we need a context
23 and do not need to worry about concurrency. */
24 static struct rrd_context global_ctx = {
25 MAXLEN,
26 ERRBUFLEN,
27 rrd_error,
28 rrd_liberror
29 };
31 /* #include <stdarg.h> */
33 struct rrd_context *rrd_get_context(
34 void)
35 {
36 if (!rrd_context_init) {
37 rrd_context_init = 1;
38 global_ctx.rrd_error[0] = '\0';
39 global_ctx.lib_errstr[0] = '\0';
40 }
41 return &global_ctx;
42 }
44 /* how ugly that is!!! - make sure strerror is what it should be. It
45 might be redefined to help in keeping other modules thread safe by
46 silently turning misplaced strerror into rrd_strerror, but here
47 this turns recursive! */
48 #undef strerror
49 const char *rrd_strerror(
50 int err)
51 {
52 return strerror(err);
53 }