From: Matthew Fernandez Date: Sun, 14 Aug 2022 21:21:54 +0000 (-0700) Subject: sfio sfopen: remove 'f' parameter that is always 'NULL' X-Git-Tag: 5.0.1~1^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f4cb404a9d87405f216e7dea1e0887de9d6e7e5;p=graphviz sfio sfopen: remove 'f' parameter that is always 'NULL' --- diff --git a/lib/expr/exgram.h b/lib/expr/exgram.h index 8f3e24202..21ae82962 100644 --- a/lib/expr/exgram.h +++ b/lib/expr/exgram.h @@ -834,7 +834,7 @@ expush(Expr_t* p, const char* name, int line, const char* sp, Sfio_t* fp) in->close = 0; else if (name) { - if (!(s = pathfind(name, p->disc->lib, p->disc->type, buf, sizeof(buf))) || !(in->fp = sfopen(NULL, s, "r"))) + if (!(s = pathfind(name, p->disc->lib, p->disc->type, buf, sizeof(buf))) || !(in->fp = sfopen(s, "r"))) { exerror("%s: file not found", name); in->bp = in->sp = ""; diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 484dac0e9..6047583b0 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -606,7 +606,7 @@ int writeFile(Agraph_t * g, char *f, Agiodisc_t* io) exerror("NULL string passed to writeG"); return 1; } - fp = sfopen(0, f, "w"); + fp = sfopen(f, "w"); if (!fp) { exwarn("Could not open %s for writing in writeG", f); return 1; @@ -629,7 +629,7 @@ Agraph_t *readFile(char *f) exerror("NULL string passed to readG"); return 0; } - fp = sfopen(0, f, "r"); + fp = sfopen(f, "r"); if (!fp) { exwarn("Could not open %s for reading in readG", f); return 0; @@ -678,7 +678,7 @@ int openFile(Expr_t * ex, const char *fname, const char *mode) exerror("openF: no available descriptors"); return -1; } - ex->file[idx] = sfopen(0, fname, mode); + ex->file[idx] = sfopen(fname, mode); if (ex->file[idx]) return idx; else diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index cc11418b3..d824174c3 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -2278,17 +2278,17 @@ static Exnode_t *compile(Expr_t * prog, char *src, char *input, int line, /* create input stream */ if (sfx) { - sf = sfopen(0, sfx, "rs"); + sf = sfopen(sfx, "rs"); if (input) { - prefix = sfopen(0, input, "rs"); + prefix = sfopen(input, "rs"); sfstack(sf, prefix); } } else - sf = sfopen(0, input, "rs"); + sf = sfopen(input, "rs"); /* prefixing label if necessary */ if (lbl) { - prefix = sfopen(0, 0, "sr+"); + prefix = sfopen(0, "sr+"); sfprintf(prefix, "%s:\n", lbl); sfseek(prefix, 0, 0); sfstack(sf, prefix); diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index 24598f396..b5cacd47f 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -80,7 +80,7 @@ static Sfio_t *openOut(char *name) { Sfio_t *outs; - outs = sfopen(0, name, "w"); + outs = sfopen(name, "w"); if (outs == 0) { error(ERROR_ERROR, "could not open %s for writing", name); } @@ -849,7 +849,7 @@ static void chkClose(Agraph_t * g) static void *ing_open(char *f) { - return sfopen(0, f, "r"); + return sfopen(f, "r"); } static Agraph_t *ing_read(void *fp) diff --git a/lib/gvpr/parse.c b/lib/gvpr/parse.c index 254fb6299..3bc3281ba 100644 --- a/lib/gvpr/parse.c +++ b/lib/gvpr/parse.c @@ -493,7 +493,7 @@ parse_prog *parseProg(char *input, int isFile) prog->source = NULL; /* command line */ } - str = sfopen(0, input, mode); + str = sfopen(input, mode); if (!str) { if (isFile) error(ERROR_ERROR, "could not open %s for reading", input); diff --git a/lib/sfio/sfio.h b/lib/sfio/sfio.h index 3d6fb496a..38afa40a5 100644 --- a/lib/sfio/sfio.h +++ b/lib/sfio/sfio.h @@ -191,7 +191,7 @@ extern "C" { extern Sfio_t *sfnew(Sfio_t *, void *, size_t, int, int); - extern Sfio_t *sfopen(Sfio_t *, const char *, const char *); + extern Sfio_t *sfopen(const char *, const char *); extern Sfio_t *sfstack(Sfio_t *, Sfio_t *); extern Sfio_t *sfswap(Sfio_t *, Sfio_t *); extern int sfsync(Sfio_t *); diff --git a/lib/sfio/sfopen.c b/lib/sfio/sfopen.c index d1dad6906..cda11e2ec 100644 --- a/lib/sfio/sfopen.c +++ b/lib/sfio/sfopen.c @@ -15,18 +15,15 @@ #endif /* Open a file/string for IO. -** If f is not nil, it is taken as an existing stream that should be -** closed and its structure reused for the new stream. ** ** Written by Kiem-Phong Vo. */ /** - * @param f old stream structure * @param file file/string to be opened * @param mode mode of the stream */ -Sfio_t *sfopen(Sfio_t * f, const char *file, const char *mode) +Sfio_t *sfopen(const char *file, const char *mode) { int fd, oldfd, oflags, sflags; @@ -36,42 +33,9 @@ Sfio_t *sfopen(Sfio_t * f, const char *file, const char *mode) /* usually used on the standard streams to change control flags */ -#ifndef _WIN32 - if (f && !file && (f->mode & SF_INIT)) { - SFMTXSTART(f, NULL); - - if (f->mode & SF_INIT) { /* paranoia in case another thread snuck in */ - if (f->file >= 0 && !(f->flags & SF_STRING) && (oflags &= (O_TEXT | O_BINARY | O_APPEND)) != 0) { /* set the wanted file access control flags */ - int ctl = fcntl(f->file, F_GETFL, 0); - ctl = (ctl & ~(O_TEXT | O_BINARY | O_APPEND)) | oflags; - fcntl(f->file, F_SETFL, ctl); - } - /* set all non read-write flags */ - f->flags |= (sflags & (SF_FLAGS & ~SF_RDWR)); - - /* reset read/write modes */ - if ((sflags &= SF_RDWR) != 0) { - f->flags = (f->flags & ~SF_RDWR) | sflags; - - if ((f->flags & SF_RDWR) == SF_RDWR) - f->bits |= SF_BOTH; - else - f->bits &= (unsigned short)~SF_BOTH; - - if (f->flags & SF_READ) - f->mode = (f->mode & ~SF_WRITE) | SF_READ; - else - f->mode = (f->mode & ~SF_READ) | SF_WRITE; - } - - SFMTXRETURN(f, f); - } else - SFMTXRETURN(f, NULL); - } - -#endif + Sfio_t *f = NULL; if (sflags & SF_STRING) { - f = sfnew(f, (char *)file, file ? strlen(file) : SF_UNBOUND, -1, sflags); + f = sfnew(NULL, (char *)file, file ? strlen(file) : SF_UNBOUND, -1, sflags); } else { if (!file) return NULL;