make basename work
[rrdtool.git] / src / rrd_graph.c
index db7d535..a24889f 100644 (file)
@@ -6,6 +6,7 @@
 
 
 #include <sys/stat.h>
+#include <libgen.h>
 
 #ifdef WIN32
 #include "strftime.h"
@@ -3682,14 +3683,11 @@ rrd_info_t *rrd_graph_v(
 
     if (im.imginfo) {
         rrd_infoval_t info;
+        char     *path;
         char     *filename;
 
-        filename = im.graphfile + strlen(im.graphfile);
-        while (filename > im.graphfile) {
-            if (*(filename - 1) == '/' || *(filename - 1) == '\\')
-                break;
-            filename--;
-        }
+        path = strdup(im.graphfile);
+        filename = basename(path);
         info.u_str =
             sprintf_alloc(im.imginfo,
                           filename,
@@ -3697,6 +3695,7 @@ rrd_info_t *rrd_graph_v(
                                   im.ximg), (long) (im.zoom * im.yimg));
         grinfo_push(&im, sprintf_alloc("image_info"), RD_I_STR, info);
         free(info.u_str);
+        free(path);
     }
     if (im.rendered_image) {
         rrd_infoval_t img;
@@ -4172,7 +4171,7 @@ void rrd_graph_options(
                         if (size > 0) {
                             rrd_set_font_desc(im,propidx,NULL,size);   
                         }
-                        if ((int) strlen(optarg) > end) {
+                        if ((int) strlen(optarg) > end+2) {
                             if (optarg[end] == ':') {
                                 rrd_set_font_desc(im,propidx,optarg + end + 1,0);   
                             } else {