From: Manuel Luis Sanmartin Rozada Date: Mon, 5 Aug 2013 23:05:01 +0000 (+0200) Subject: csv plugin: fix forgotten "datadir" in re-implement value_list_to_filename() X-Git-Tag: collectd-5.4.0~1^2^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=44dcf2017576cbd398574ac66a732a5d2b179c3c;p=collectd.git csv plugin: fix forgotten "datadir" in re-implement value_list_to_filename() In the commit 7f90e30 the re-implementation of value_list_to_filename forgot to prepend the datadir string. Signed-off-by: Florian Forster --- diff --git a/src/csv.c b/src/csv.c index afb4f833..f123c5d6 100644 --- a/src/csv.c +++ b/src/csv.c @@ -126,12 +126,25 @@ static int value_list_to_filename (char *buffer, size_t buffer_size, { int status; - char *ptr; - size_t ptr_size; + char *ptr = buffer; + size_t ptr_size = buffer_size; time_t now; struct tm struct_tm; - status = FORMAT_VL (buffer, buffer_size, vl); + if (datadir != NULL) + { + size_t len = strlen (datadir) + 1; + + if (len >= ptr_size) + return (ENOBUFS); + + memcpy (ptr, datadir, len); + ptr[len-1] = '/'; + ptr_size -= len; + ptr += len; + } + + status = FORMAT_VL (ptr, ptr_size, vl); if (status != 0) return (status); @@ -140,8 +153,8 @@ static int value_list_to_filename (char *buffer, size_t buffer_size, if (use_stdio) return (0); - ptr_size = buffer_size - strlen (buffer); - ptr = buffer + strlen (buffer); + ptr_size -= strlen (ptr); + ptr += strlen (ptr); /* "-2013-07-12" => 11 bytes */ if (ptr_size < 12)