X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_info.c;h=13d30a6cd37fed0a5d70b3376882adaf7c68b1b5;hb=daf8e7ff715a59e1f9827080d1b785ffb3c5a4b1;hp=ff3e35be452e704a55a2fc954feb037a877b7a4f;hpb=c208ca2237941e0390dafb6714b2e06f1f776394;p=rrdtool.git diff --git a/src/rrd_info.c b/src/rrd_info.c index ff3e35b..13d30a6 100644 --- a/src/rrd_info.c +++ b/src/rrd_info.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.99907080300 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3rc7 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_info Get Information about the configuration of an RRD *****************************************************************************/ @@ -20,18 +20,14 @@ char *sprintf_alloc( char *fmt, ...) { -#ifdef HAVE_VSNPRINTF - int maxlen = 50; -#else - int maxlen = 1000; -#endif + int maxlen = 1024 + strlen(fmt); char *str = NULL; va_list argp; - str = malloc(sizeof(char) * (strlen(fmt) + maxlen)); + str = malloc(sizeof(char) * (maxlen+1)); if (str != NULL) { va_start(argp, fmt); #ifdef HAVE_VSNPRINTF - vsnprintf(str, maxlen - 1, fmt, argp); + vsnprintf(str, maxlen, fmt, argp); #else vsprintf(str, fmt, argp); #endif @@ -71,6 +67,12 @@ info_t next->value.u_str = malloc(sizeof(char) * (strlen(value.u_str) + 1)); strcpy(next->value.u_str, value.u_str); break; + case RD_I_BLO: + next->value.u_blo.size = value.u_blo.size; + next->value.u_blo.ptr = + malloc(sizeof(unsigned char) * value.u_blo.size); + memcpy(next->value.u_blo.ptr, value.u_blo.ptr, value.u_blo.size); + break; } return (next); } @@ -323,3 +325,56 @@ info_t *rrd_info_r( rrd_free(&rrd); return (data); } + + +void info_print( + info_t *data) +{ + while (data) { + printf("%s = ", data->key); + + switch (data->type) { + case RD_I_VAL: + if (isnan(data->value.u_val)) + printf("NaN\n"); + else + printf("%0.10e\n", data->value.u_val); + break; + case RD_I_CNT: + printf("%lu\n", data->value.u_cnt); + break; + case RD_I_INT: + printf("%d\n", data->value.u_int); + break; + case RD_I_STR: + printf("\"%s\"\n", data->value.u_str); + break; + case RD_I_BLO: + printf("BLOB_SIZE:%lu\n", data->value.u_blo.size); + fwrite(data->value.u_blo.ptr, data->value.u_blo.size, 1, stdout); + break; + } + data = data->next; + } +} + +void info_free( + info_t *data) +{ + info_t *save; + + while (data) { + save = data; + if (data->key) { + if (data->type == RD_I_STR) { + free(data->value.u_str); + } + if (data->type == RD_I_BLO) { + free(data->value.u_blo.ptr); + } + free(data->key); + } + data = data->next; + free(save); + } +}