[rrd-developers] Fix to 'graph' when redirecting to stdout on Windows

Shane O'Donnell shaneo at opennms.org
Thu Feb 1 16:21:37 MET 2001


There is a problem in the rrd_graph() function when running on Windows.
When using a "-" in place of the filename parameter in order
to force the output from the 'graph' command to be sent to stdout
all the linefeed characters (0x0A)are replaced with carriage return
plus linefeed characters (0x0D 0x0A).  This causes the resulting
gif/png files to be corrupt.

The problem is that stdout is opened in TEXT TRANSLATION mode
by default as opposed to BINARY mode.  On Linux/UNIX this
isn't an issue but on Windows it is.  We were able to fix this
by adding a call to _setmode() to change the mode to BINARY.

The following code in rrd_graph.c:

if (strcmp(im->graphfile,"-")==0) {
fo = stdout;
} else {
if ((fo = fopen(im->graphfile,"wb")) == NULL) {
rrd_set_error("Openin %s for write: %s",im->graphfile, strerror(errno));
return (-1);
}

was changed to:

if (strcmp(im->graphfile,"-")==0) {
#ifdef WIN32
/* Change translation mode for stdout to BINARY */
_setmode( _fileno( stdout ), O_BINARY );
#endif
fo = stdout;
} else {
if ((fo = fopen(im->graphfile,"wb")) == NULL) {
    rrd_set_error("Openin %s for write: %s",im->graphfile,
strerror(errno));
    return (-1);
}

Also, the following include statements are needed:

#ifdef WIN32
#include <io.h>
#include <fcntl.h>
#endif

If someone can suggest a better way for me to incorporate this code, please
let me know.  Otherwise, I'd love it if we could get this code into the next
minor release.

Thanks all,

Shane O.
========
Shane O'Donnell
OpenNMS.org
shaneo at opennms.org
==================


--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list