Patch for rrd_context system by sebastian harl, making it simpler and less error...
[rrdtool.git] / src / rrd_thread_safe.c
index 074a873..3138cc8 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * RRDtool 1.2.23  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.3rc7  Copyright by Tobi Oetiker, 1997-2008
  * This file:     Copyright 2003 Peter Stamfest <peter@stamfest.at> 
  *                             & Tobias Oetiker
  * Distributed under the GPL
@@ -35,7 +35,7 @@ static void context_destroy_context(
 
 /* Allocate the key */
 static void context_get_key(
-    )
+    void)
 {
     pthread_key_create(&context_key, context_destroy_context);
 }
@@ -60,7 +60,7 @@ const char *rrd_strerror(
 {
     struct rrd_context *ctx = rrd_get_context();
 
-    if (strerror_r(err, ctx->lib_errstr, ctx->errlen))
+    if (strerror_r(err, ctx->lib_errstr, sizeof(ctx->lib_errstr)))
         return "strerror_r failed. sorry!";
     else
         return ctx->lib_errstr;
@@ -75,8 +75,8 @@ const char *rrd_strerror(
 
     ctx = rrd_get_context();
     pthread_mutex_lock(&mtx);
-    strncpy(ctx->lib_errstr, strerror(err), ctx->errlen);
-    ctx->lib_errstr[ctx->errlen] = '\0';
+    strncpy(ctx->lib_errstr, strerror(err), sizeof(ctx->lib_errstr));
+    ctx->lib_errstr[sizeof(ctx->lib_errstr) - 1] = '\0';
     pthread_mutex_unlock(&mtx);
     return ctx->lib_errstr;
 }