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 = "";
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;
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;
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
/* 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);
{
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);
}
static void *ing_open(char *f)
{
- return sfopen(0, f, "r");
+ return sfopen(f, "r");
}
static Agraph_t *ing_read(void *fp)
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);
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 *);
#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;
/* 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;