From aede8ce4ce1acdaa3d68a06ca40bd9543f96169f Mon Sep 17 00:00:00 2001 From: ellson Date: Thu, 26 Feb 2009 13:08:02 +0000 Subject: [PATCH] Simplify output discipline slightly by using system fwrite()'s template exactly. --- lib/graph/attribs.c | 15 ++------------- lib/graph/graph.h | 4 +++- lib/graph/graphio.c | 15 +++++++++------ lib/graph/libgraph.h | 4 ++-- lib/gvc/gvdevice.c | 12 +++++++++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/graph/attribs.c b/lib/graph/attribs.c index 35fe9948b..72954d63c 100644 --- a/lib/graph/attribs.c +++ b/lib/graph/attribs.c @@ -324,17 +324,6 @@ Agsym_t *agprvattr(void *obj, Agsym_t *a) return (Agsym_t *)dtprev(dict->dict, a); } -static size_t agfwrite(FILE *fp, const char *s, size_t len) -{ - return fwrite(s, sizeof(char), len, fp); -} - -static int agferror(FILE *fp) -{ - return ferror(fp); -} - - /* this is normally called by the aginit() macro */ void aginitlib(int gs, int ns, int es) { @@ -343,8 +332,8 @@ void aginitlib(int gs, int ns, int es) AG.node_nbytes = ns; AG.edge_nbytes = es; AG.init_called = TRUE; - AG.fwrite = agfwrite; - AG.ferror = agferror; + AG.fwrite = fwrite; /* init to system version of fwrite() */ + AG.ferror = ferror; /* init to system version of ferror() */ initproto(); } else if ((AG.graph_nbytes != gs) || (AG.node_nbytes != ns) diff --git a/lib/graph/graph.h b/lib/graph/graph.h index 824493e83..52ed60dbe 100644 --- a/lib/graph/graph.h +++ b/lib/graph/graph.h @@ -163,7 +163,9 @@ extern "C" { extern void agreadline(int); extern void agsetfile(char *); extern Agraph_t *agmemread(char *); - extern void agsetodisc(size_t (*fwrite) (FILE *fp, const char *s, size_t len), int (*ferror) (FILE *fp)); + extern void agsetodisc( + size_t (*myfwrite) (const void *ptr, size_t size, size_t nmemb, FILE *stream), + int (*myferror) (FILE *stream) ); extern void agfprintf(FILE *fp, const char *format, ...); extern int agputs(const char *s, FILE *fp); extern int agputc(int c, FILE *fp); diff --git a/lib/graph/graphio.c b/lib/graph/graphio.c index 4edef00a2..f97d4d3d3 100644 --- a/lib/graph/graphio.c +++ b/lib/graph/graphio.c @@ -177,10 +177,13 @@ char *agstrcanon(char *arg, char *buf) return (_agstrcanon(arg, buf)); } -void agsetodisc(size_t (*fwrite) (FILE *fp, const char *s, size_t len), int (*ferror) (FILE *fp)) +void agsetodisc( + size_t (*myfwrite) (const void *ptr, size_t size, size_t nmemb, FILE *stream), + int (*myferror) (FILE *stream) +) { - AG.fwrite = fwrite; - AG.ferror = ferror; + AG.fwrite = myfwrite; + AG.ferror = myferror; } /* agfprintf: @@ -204,14 +207,14 @@ void agfprintf(FILE *fp, const char *format, ...) #endif va_end(argp); - AG.fwrite(fp, buf, len); + AG.fwrite(buf, sizeof(char), len, fp); } int agputs(const char *s, FILE *fp) { size_t len = strlen(s); - if (AG.fwrite(fp, s, len) != len) { + if (AG.fwrite(s, sizeof(char), len, fp) != len) { return EOF; } return +1; @@ -222,7 +225,7 @@ int agputc(int c, FILE *fp) { const char cc = c; - if (AG.fwrite (fp, &cc, 1) != 1) { + if (AG.fwrite (&cc, sizeof(char), 1, fp) != 1) { return EOF; } return c; diff --git a/lib/graph/libgraph.h b/lib/graph/libgraph.h index ec1ce104e..83563a070 100644 --- a/lib/graph/libgraph.h +++ b/lib/graph/libgraph.h @@ -129,8 +129,8 @@ extern "C" { char *linebuf; short syntax_errors; unsigned char accepting_state, init_called; - size_t (*fwrite) (FILE *fp, const char *s, size_t len); - int (*ferror) (FILE *fp); + size_t (*fwrite) (const void *ptr, size_t size, size_t nmemb, FILE *stream); + int (*ferror) (FILE *stream); } AG; /* follow structs used in graph parser */ diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 1b39e3d80..af5cac645 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -252,14 +252,20 @@ size_t gvwrite (GVJ_t * job, const char *s, size_t len) return len; } -int gvferror (FILE* fp) +int gvferror (FILE* stream) { + GVJ_t *job = (GVJ_t*)stream; + + if (!job->gvc->write_fn && !job->output_data) + return ferror(job->output_file); + return 0; } -size_t gvfwrite (FILE* fp, const char *s, size_t len) +size_t gvfwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) { - return gvwrite((GVJ_t*)fp, s, len); + assert(size = sizeof(char)); + return gvwrite((GVJ_t*)stream, ptr, nmemb); } int gvputs(GVJ_t * job, const char *s) -- 2.40.0