From: ellson Date: Wed, 3 Oct 2007 21:18:43 +0000 (+0000) Subject: add gvdevice_write() for use from bitmap libraries X-Git-Tag: LAST_LIBGRAPH~32^2~5221 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d377c64891d00a60dc6d7f7cb73053b82a2ea19;p=graphviz add gvdevice_write() for use from bitmap libraries --- diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 0aec1147a..9143f3f11 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -48,20 +48,23 @@ #include "gvcint.h" #include "gvcproc.h" -/* gvdevice selection is done in gvrender_select() in gvrender.c */ -void gvdevice_fputs(GVJ_t * job, char *s) +size_t gvdevice_write (GVJ_t * job, char *s, unsigned int len) { - int len, rc; - - len = strlen(s); if (job->flags & GVDEVICE_COMPRESSED_FORMAT) { #ifdef HAVE_LIBZ - gzwrite((gzFile *) (job->output_file), s, (unsigned) len); + return gzwrite((gzFile *) (job->output_file), s, len); #endif } else - rc = fwrite(s, sizeof(char), (unsigned) len, job->output_file); + return fwrite(s, sizeof(char), len, job->output_file); +} + +/* gvdevice selection is done in gvrender_select() in gvrender.c */ + +void gvdevice_fputs(GVJ_t * job, char *s) +{ + gvdevice_write (job, s, strlen(s)); } /* gvdevice_printf: @@ -74,20 +77,20 @@ void gvdevice_fputs(GVJ_t * job, char *s) void gvdevice_printf(GVJ_t * job, const char *format, ...) { char buf[BUFSIZ]; + unsigned int len; va_list argp; va_start(argp, format); #ifdef HAVE_VSNPRINTF - (void) vsnprintf(buf, sizeof(buf), format, argp); + len = vsnprintf(buf, sizeof(buf), format, argp); #else - (void) vsprintf(buf, format, argp); + len = vsprintf(buf, format, argp); #endif va_end(argp); - gvdevice_fputs(job, buf); + gvdevice_write(job, buf, len); } - static void auto_output_filename(GVJ_t *job) { static char *buf; @@ -139,7 +142,7 @@ void gvdevice_initialize(GVJ_t * job) gvde->initialize(job); } else { - /* if the device has now initialization then it uses file output */ + /* if the device has no initialization then it uses file output */ if (!job->output_file) { /* if not yet opened */ if (gvc->common.auto_outfile_names) auto_output_filename(job);