if (im == NULL)
return 0;
+ free(im->graphfile);
+
if (im->daemon_addr != NULL)
free(im->daemon_addr);
if (im->lazy == 0)
return 0; /* no lazy option */
- if (strlen(im->graphfile) == 0)
+ if (im->graphfile == NULL)
return 0; /* inmemory option */
if (stat(im->graphfile, &imgstat) != 0)
return 0; /* can't stat */
#ifdef CAIRO_HAS_PDF_SURFACE
case IF_PDF:
im->gridfit = 0;
- im->surface = strlen(im->graphfile)
+ im->surface = im->graphfile
? cairo_pdf_surface_create(im->graphfile, im->ximg * im->zoom,
im->yimg * im->zoom)
: cairo_pdf_surface_create_for_stream
#ifdef CAIRO_HAS_PS_SURFACE
case IF_EPS:
im->gridfit = 0;
- im->surface = strlen(im->graphfile)
+ im->surface = im->graphfile
?
cairo_ps_surface_create(im->graphfile, im->ximg * im->zoom,
im->yimg * im->zoom)
#ifdef CAIRO_HAS_SVG_SURFACE
case IF_SVG:
im->gridfit = 0;
- im->surface = strlen(im->graphfile)
+ im->surface = im->graphfile
?
cairo_svg_surface_create(im->
graphfile,
{
cairo_status_t status;
- status = strlen(im->graphfile) ?
+ status = im->graphfile ?
cairo_surface_write_to_png(im->surface, im->graphfile)
: cairo_surface_write_to_png_stream(im->surface, &cairo_output,
im);
if (status != CAIRO_STATUS_SUCCESS) {
- rrd_set_error("Could not save png to '%s'", im->graphfile);
+ rrd_set_error("Could not save png to '%s'",
+ im->graphfile ? im->graphfile : "memory");
return 1;
}
break;
case IF_JSONTIME:
break;
default:
- if (strlen(im->graphfile)) {
+ if (im->graphfile) {
cairo_show_page(im->cr);
} else {
cairo_surface_finish(im->surface);
return NULL;
}
- if (strlen(argv[optind]) >= MAXPATH) {
- rrd_set_error("filename (including path) too long");
- rrd_info_free(im.grinfo);
- im_free(&im);
- return NULL;
- }
-
- strncpy(im.graphfile, argv[optind], MAXPATH - 1);
- im.graphfile[MAXPATH - 1] = '\0';
-
- if (strcmp(im.graphfile, "-") == 0) {
- im.graphfile[0] = '\0';
- }
+ if (strcmp(argv[optind], "-") != 0) {
+ im.graphfile = strdup(argv[optind]);
+ if (im.graphfile == NULL) {
+ rrd_set_error("cannot allocate sufficient memory for filename length");
+ rrd_info_free(im.grinfo);
+ im_free(&im);
+ return NULL;
+ }
+ } /* else we work in memory: im.graphfile==NULL */
rrd_graph_script(argc, argv, &im, optind+1);
if (im.imginfo && *im.imginfo) {
rrd_infoval_t info;
- char *path;
+ char *path = NULL;
char *filename;
if (bad_format_imginfo(im.imginfo)) {
im_free(&im);
return NULL;
}
- path = strdup(im.graphfile);
- filename = basename(path);
+ if (im.graphfile) {
+ path = strdup(im.graphfile);
+ filename = basename(path);
+ } else {
+ filename = "memory";
+ }
info.u_str =
sprintf_alloc(im.imginfo,
filename,
#include <glib.h>
-#ifdef WIN32
-# include <windows.h>
-# define MAXPATH MAX_PATH
-#endif
-
#define ALTYGRID 0x01 /* use alternative y grid algorithm */
#define ALTAUTOSCALE 0x02 /* use alternative algorithm to find lower and upper bounds */
#define ALTAUTOSCALE_MIN 0x04 /* use alternative algorithm to find lower bounds */
typedef struct image_desc_t {
/* configuration of graph */
- char graphfile[MAXPATH]; /* filename for graphic */
+ char *graphfile; /* filename for graphic */
enum gfx_type_en graph_type; /* type of the graph */
long xsize, ysize; /* graph area size in pixels */
struct gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */