Code

use basename to determine filename for imginfo as suggested by sebastian
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 9 Nov 2008 00:00:33 +0000 (00:00 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 9 Nov 2008 00:00:33 +0000 (00:00 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1662 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_graph.c
src/rrd_graph.h

index 4e05d04dc3ad20e25166fce97d0a7a90535acbed..65c3807377ff5ba88fc5606856ebab44c17f1df7 100644 (file)
@@ -3180,6 +3180,7 @@ rrd_graph(int argc, char **argv, char ***prdata, int *xsize, int *ysize, FILE *s
     *ymax=im.maxval;
     if (im.imginfo) {
         char *filename;
+        char *path;
         if (!(*prdata)) {
             /* maybe prdata is not allocated yet ... lets do it now */
             if ((*prdata = calloc(2,sizeof(char *)))==NULL) {
@@ -3192,13 +3193,10 @@ rrd_graph(int argc, char **argv, char ***prdata, int *xsize, int *ysize, FILE *s
             rrd_set_error("malloc imginfo");
             return -1;
         }
-        filename=im.graphfile+strlen(im.graphfile);
-        while(filename > im.graphfile) {
-            if (*(filename-1)=='/' || *(filename-1)=='\\' ) break;
-            filename--;
-        }
-
+        path = strdup(im.graphfile);
+        filename = basename(path);
         sprintf((*prdata)[0],im.imginfo,filename,(long)(im.canvas->zoom*im.ximg),(long)(im.canvas->zoom*im.yimg));
+        free(path);
     }
     im_free(&im);
     return 0;
index 56308bb8c293685f3e69303d98a7f26489d5de57..04f1d7cd68a35e6f9649a182b1dbe72606b043be 100644 (file)
@@ -4,6 +4,7 @@
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 #include "rrd_gfx.h"
+#include <libgen.h>
 
 #define MAX_VNAME_LEN 255
 #define DEF_NAM_FMT "%255[-_A-Za-z0-9]"