Beispiel #1
0
tmain()
{
	char	buf[100];
	Sfio_t	*fp;
	int	i;
	char	*s;

	if(!(fp = sftmp(8)))
		terror("Can't open temp file");

	sfset(fp,SF_LINE,1);
	for(i = 0; i < 1000; ++i)
	{	sfsprintf(buf,sizeof(buf),"Number: %d",i);
		if(sfputr(fp,buf,'\n') <= 0)
			terror("Writing %s",buf);
	}

	sfseek(fp,(Sfoff_t)0,0);

	for(i = 0; i < 1000; ++i)
	{	sfsprintf(buf,sizeof(buf),"Number: %d",i);
		if(!(s = sfgetr(fp,'\n',1)))
			terror("Reading %s",buf);
		if(strcmp(s,buf) != 0)
			terror("Input=%s, Expect=%s",s,buf);
	}

	sfseek(fp,(Sfoff_t)0,0);
	s = sfgetr(fp,'\0',1);
	if(s)
		terror("Expecting a null string");
	s = sfgetr(fp,'\0',-1);
	if(!s)
		terror("Expecting a non-null string");
	if(sfvalue(fp) != sfsize(fp))
		terror("Wrong size");

	sfclose(fp);
	if(!(fp = sfnew(0, buf, 12, 1, SF_WRITE)) )
		terror("Opening a test stream");
	sfsetbuf(fp, buf, 12);
	sfset(fp, SF_LINE, 0);
	sfdisc(fp, &Disc);
	if(sfputr(fp, "0123456789", '\n') != 11)
		terror("Sfputr failed1");
	if(sfputr(fp, "0", -1) != 1)
		terror("Sfputr failed2");
	if(sfputr(fp, "1", -1) != 1)
		terror("Sfputr failed3");

	texit(0);
}
Beispiel #2
0
static void openFirstGeneralFile(generalStream_s *gs)
{
  if (gs->sio) {
    gs->fp = sfstdin;
    gs->fpLen = -1;
  }
  else {
    gs->fp = HRSopenfile(gs->fileNames[0], "r");
    gs->fpLen = sfsize(gs->fp);
  }

  gs->count = 0;
}
Beispiel #3
0
main()
{
    void*	s;
    size_t	size;
    off_t	total;

    if (!(s = sfreserve(sfstdin, SF_UNBOUND, 0)))
    {
        sfprintf(sfstderr, "read error\n");
        return 1;
    }
    size = sfvalue(sfstdin);
    total = sfsize(sfstdin);
    sfprintf(sfstdout, "%d\n", recfmt(s, size, total));
    return 0;
}
Beispiel #4
0
MAIN()
{
	char	buf[100];
	Sfio_t	*fp;
	int	i;
	char	*s;

	if(!(fp = sftmp(8)))
		terror("Can't open temp file\n");

	sfset(fp,SF_LINE,1);
	for(i = 0; i < 1000; ++i)
	{	sfsprintf(buf,sizeof(buf),"Number: %d",i);
		if(sfputr(fp,buf,'\n') <= 0)
			terror("Writing %s\n",buf);
	}

	sfseek(fp,(Sfoff_t)0,0);

	for(i = 0; i < 1000; ++i)
	{	sfsprintf(buf,sizeof(buf),"Number: %d",i);
		if(!(s = sfgetr(fp,'\n',1)))
			terror("Reading %s\n",buf);
		if(strcmp(s,buf) != 0)
			terror("Input=%s, Expect=%s\n",s,buf);
	}

	sfseek(fp,(Sfoff_t)0,0);
	s = sfgetr(fp,'\0',1);
	if(s)
		terror("Expecting a null string\n");
	s = sfgetr(fp,'\0',-1);
	if(!s)
		terror("Expecting a non-null string\n");
	if(sfvalue(fp) != sfsize(fp))
		terror("Wrong size\n");

	TSTEXIT(0);
}
Beispiel #5
0
/* is there stuff left?  if not, go to next file */
static int advFile(generalStream_s *gs)
{
  if (gs->fpLen == -1) {
    int c = sfgetc(gs->fp);
    if (c == EOF)
      return 0;
    sfungetc(gs->fp, c);
    return 1;
  } else {
    if (sftell(gs->fp) == gs->fpLen) {
      while (++gs->count < gs->numFilesinStream) {
	HRSclosefile(gs->fp);
	gs->fp = HRSopenfile(gs->fileNames[gs->count], "r");
	gs->fpLen = sfsize(gs->fp);
	if (gs->fpLen != 0)
	  return 1;
      }
      return 0;
    }

    return 1;
  }
  
}
Beispiel #6
0
Dssfile_t*
dssfopen(Dss_t* dss, const char* path, Sfio_t* io, Dssflags_t flags, Dssformat_t* format)
{
	Dssfile_t*	file;
	Vmalloc_t*	vm;
	char*		s;
	size_t		n;
	int		i;
	struct stat	st;
	Sfdisc_t	top;
	char		buf[PATH_MAX];

	if (flags & DSS_FILE_WRITE)
	{
		if (io)
		{
			memset(&top, 0, sizeof(top));
			if (sfdisc(io, &top))
			{
				n = top.disc == &dss->state->compress_preferred;
				sfdisc(io, SF_POPDISC);
				if (n)
				{
					sfdisc(io, SF_POPDISC);
					sfdczip(io, path, dss->meth->compress ? dss->meth->compress : "gzip", dss->disc->errorf);
				}
			}
		}
		if (dss->flags & DSS_APPEND)
			flags |= DSS_FILE_APPEND;
	}
	if (!path || !*path || streq(path, "-"))
	{
		if (flags & DSS_FILE_WRITE)
		{
			if (io)
				path = "output-stream";
			else
			{
				path = "/dev/stdout";
				io = sfstdout;
			}
		}
		else if (io)
			path = "input-stream";
		else
		{
			path = "/dev/stdin";
			io = sfstdin;
		}
		flags |= DSS_FILE_KEEP;
	}
	else if (io)
		flags |= DSS_FILE_KEEP;
	else if (flags & DSS_FILE_WRITE)
	{
		if (!(io = sfopen(NiL, path, (flags & DSS_FILE_APPEND) ? "a" : "w")))
		{
			if (dss->disc->errorf)
				(*dss->disc->errorf)(NiL, dss->disc, ERROR_SYSTEM|2, "%s: cannot open", path);
			return 0;
		}
	}
	else if (!(io = dssfind(path, "", DSS_VERBOSE, buf, sizeof(buf), dss->disc)))
		return 0;
	else
		path = (const char*)buf;
	if (!(vm = vmopen(Vmdcheap, Vmbest, 0)))
	{
		if (dss->disc->errorf)
			(*dss->disc->errorf)(NiL, dss->disc, ERROR_SYSTEM|2, "out of space");
		return 0;
	}
	if (!(file = vmnewof(vm, 0, Dssfile_t, 1, strlen(path) + 1)))
	{
		if (dss->disc->errorf)
			(*dss->disc->errorf)(NiL, dss->disc, ERROR_SYSTEM|2, "out of space");
		if (!(flags & DSS_FILE_KEEP))
			sfclose(io);
		vmclose(vm);
		return 0;
	}
	strcpy(file->path = (char*)(file + 1), path);
	file->dss = dss;
	file->vm = vm;
	file->io = io;
	file->flags = flags;
	if (flags & DSS_FILE_WRITE)
	{
		if (!(file->format = format) && !(file->format = dss->format))
		{
			if (dss->disc->errorf)
				(*dss->disc->errorf)(NiL, dss->disc, 2, "output method format must be specified");
			if (!(flags & DSS_FILE_KEEP))
				sfclose(io);
			return 0;
		}
		file->readf = noreadf;
		file->writef = file->format->writef;
	}
	else
	{
		if (sfsize(file->io) || !fstat(sffileno(file->io), &st) && (S_ISFIFO(st.st_mode)
#ifdef S_ISSOCK
			|| S_ISSOCK(st.st_mode)
#endif
			))
		{
			if (sfdczip(file->io, file->path, NiL, dss->disc->errorf) < 0)
			{
				if (dss->disc->errorf)
					(*dss->disc->errorf)(NiL, dss->disc, ERROR_SYSTEM|2, "%s: inflate error", file->path);
				dssfclose(file);
				return 0;
			}
			s = sfreserve(file->io, SF_UNBOUND, SF_LOCKR);
			n = sfvalue(file->io);
			if (!s)
			{
				if (n && dss->disc->errorf)
					(*dss->disc->errorf)(NiL, dss->disc, ERROR_SYSTEM|2, "%s: cannot peek", file->path);
				dssfclose(file);
				return 0;
			}
			for (file->format = (Dssformat_t*)dtfirst(dss->meth->formats); file->format && !(i = (*file->format->identf)(file, s, n, dss->disc)); file->format = (Dssformat_t*)dtnext(dss->meth->formats, file->format));
			sfread(file->io, s, 0);
			if (!file->format)
			{
				if (dss->disc->errorf)
					(*dss->disc->errorf)(NiL, dss->disc, 2, "%s: unknown %s format", file->path, dss->meth->name);
				dssfclose(file);
				return 0;
			}
			if (i < 0)
				return 0;
			if (format && format != file->format)
			{
				if (dss->disc->errorf)
					(*dss->disc->errorf)(NiL, dss->disc, 2, "%s: %s file format %s incompatible with %s", file->path, dss->meth->name, file->format->name, format->name);
				dssfclose(file);
				return 0;
			}
			if ((dss->flags & DSS_VERBOSE) && dss->disc->errorf)
				(*dss->disc->errorf)(dss, dss->disc, 1, "%s: %s method %s format", file->path, dss->meth->name, file->format->name);
			file->readf = file->format->readf;
		}
		else
		{
			file->format = format ? format : dss->format ? dss->format : (Dssformat_t*)dtfirst(dss->meth->formats);
			file->readf = nullreadf;
		}
		file->writef = nowritef;
		if (!dss->format)
			dss->format = file->format;
	}
	if (!file->format)
	{
		if (dss->disc->errorf)
			(*dss->disc->errorf)(NiL, dss->disc, 2, "%s: %s method did not set file format", file->path, dss->meth->name);
		dssfclose(file);
		return 0;
	}
	file->record.file = file;
	if ((*file->format->openf)(file, dss->disc))
	{
		dssfclose(file);
		return 0;
	}
	return file;
}
Beispiel #7
0
int
pzheadread(register Pz_t* pz)
{
	register int		i;
	register int		n;
	register unsigned char*	s;
	size_t			m;
	Pzpart_t*		pp;

	if (pz->flags & PZ_HEAD)
		return 0;

	/*
	 * check the header magic
	 */

	if (s = (unsigned char*)sfreserve(pz->io, 4, 1))
	{
		i = s[0];
		n = s[1];
	}
	else
		i = n = 0;
	if (pz->disc->errorf)
		(*pz->disc->errorf)(pz, pz->disc, -1, "%s: pzheadread: f=%08x i=%02x n=%02x partition=%s%s", pz->path, pz->flags, i, n, pz->disc->partition, s ? "" : " (nil)");
	if (i != PZ_MAGIC_1 || n != PZ_MAGIC_2 || s[2] == 0 || s[3] >= 10)
	{
		sfread(pz->io, s, 0);
		if (pz->flags & PZ_SPLIT)
			return 0;
		if (pz->flags & PZ_DISC)
		{
			pz->flags &= ~PZ_POP;
			return -1;
		}
		if (!(pz->flags & (PZ_READ|PZ_WRITE|PZ_STAT)) && (m = pz->prefix.count))
		{
			if (pz->prefix.terminator >= 0)
			{
				while (m-- > 0)
				{
					if (!sfgetr(pz->io, pz->prefix.terminator, 0))
					{
						if (pz->disc->errorf)
							(*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix record%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
						return -1;
					}
				}
			}
			else if (!sfreserve(pz->io, m, 0))
			{
				if (pz->disc->errorf)
					(*pz->disc->errorf)(pz, pz->disc, 2, "%s: cannot read %I*u prefix byte%s from data", pz->path, sizeof(pz->prefix.count), pz->prefix.count, pz->prefix.count == 1 ? "" : "s");
				return -1;
			}
		}
		if (!(n = pz->row))
		{
			if ((pz->flags & PZ_ACCEPT) || !sfsize(pz->io))
				n = 1;
			else if ((n = pzfixed(pz, pz->io, NiL, 0)) <= 0 && pz->disc->partition)
			{
				pz->flags |= PZ_ROWONLY;
				if (!pzpartition(pz, pz->disc->partition))
					n = pz->row;
				pz->flags &= ~PZ_ROWONLY;
			}
		}
		if (n <= 0)
		{
			if (!(pz->flags & PZ_DELAY) && (pz->disc->partition || !(pz->flags & PZ_FORCE)))
			{
				if (pz->disc->errorf)
					(*pz->disc->errorf)(pz, pz->disc, 2, "%s: unknown input format", pz->path);
				return -1;
			}
			pz->flags |= PZ_UNKNOWN;
			n = 1;
		}
		if (!(pp = vmnewof(pz->vm, 0, Pzpart_t, 1, 0)))
			return -1;
		pz->major = PZ_MAJOR;
		pz->minor = PZ_MINOR;
		pp->name = "";
		pp->row = n;
		return pzpartinit(pz, pp, NiL);
	}
	sfread(pz->io, s, 2);
	pz->flags &= ~PZ_FORCE;
	pz->major = sfgetc(pz->io);
	pz->minor = sfgetc(pz->io);
	switch (pz->major)
	{
	case 1:
		if (pz->minor <= 2)
			goto noway;
		break;
	case 2:
		pz->win = sfgetu(pz->io);
		break;
	default:
		goto noway;
	}
	pz->flags |= PZ_HEAD;
	return pzpartread(pz);
 noway:
	if (pz->disc->errorf)
		(*pz->disc->errorf)(pz, pz->disc, 2, "%s: data %d.%d not supported by implementation %d.%d", pz->path, pz->major, pz->minor, PZ_MAJOR, PZ_MINOR);
	return -1;
}
Beispiel #8
0
MAIN()
{
	int	i, n, k;
	Sfoff_t	o;
	char	buf[1024], *s;
	char	bigbuf[1024*8];
	int	fd[2];
	Sfio_t*	f;

	if(!(f = sfopen(0, tstfile(0), "w")) )
		terror("Opening file to write");
	if(sfwrite(f,"0123456789",10) != 10 || sfwrite(f,"abcdefgh",8) != 8)
		terror("Writing data");

	if(!(f = sfopen(f, tstfile(0), "r")) )
		terror("Opening file to read");
	sfsetbuf(f, buf, sizeof(buf));

	if(!(s = (char*)sfreserve(f,10,0)) )
		terror("sfreserve failed");
	if(strncmp(s,"0123456789",10) != 0)
		terror("Did not get correct data");

	if((s = (char*)sfreserve(f,10,0)) )
		terror("sfreserve should not have succeeded");
	if(sfvalue(f) != 8)
		terror("sfreserve should have left the right unread record length");

	if(!(s = (char*)sfreserve(f,4,0)) )
		terror("sfreserve should return 4 bytes");
	if(strncmp(s,"abcd",4) != 0)
		terror("Got wrong data");

	if((s = (char*)sfreserve(f,10,0)) )
		terror("sfreserve should not have succeeded2");
	if(sfvalue(f) != 4)
		terror("sfreserve should have left 4 bytes length");

	if(!(s = (char*)sfreserve(f,0,SF_LASTR)) )
		terror("sfreserve should have returned last unread record");
	if(strncmp(s,"efgh",4) != 0)
		terror("Record has wrong data");

	sfclose(f);

	sfsetbuf(sfstdout,buf,sizeof(buf));
	sfset(sfstdout,SF_SHARE|SF_PUBLIC,0);
	if((s = (char*)sfreserve(sfstdout,0,0)) != buf)
		terror("Wrong buffer\n");
	if((n = sfwrite(sfstdout,"foobar",6)) != 6)
		terror("Write failed\n");
	if((char*)sfreserve(sfstdout,0,0) != s+6)
		terror("Wrong reserved pointer\n");
	sfpurge(sfstdout);

	if(sfopen(sfstdout, tstfile(0),"w") != sfstdout)
		terror("Opening file\n");

	sfsetbuf(sfstdout,NIL(char*),0);
	if(!(s = sfreserve(sfstdout,0,1)) )
		terror("Could not lock stdout\n");
	if(sfputc(sfstdout,'1') >= 0)
		terror("stdout wasn't locked\n");
	if(sfwrite(sfstdout,s,0) != 0)
		terror("stdout can't be unlocked\n");

	sfsetbuf(sfstdout,NIL(char*),sizeof(buf)/2);

	for(i = 0; i < sizeof(buf); ++i)
		buf[i] = (i%26) + 'a';

	n = 0;
	for(i = 0; i < 33; ++i)
	{	if(!(s = sfreserve(sfstdout,sizeof(buf),1)) )
			terror("Can't reserve write buffer\n");

		memcpy(s,buf,sizeof(buf));

		if(sfwrite(sfstdout,s,sizeof(buf)) != sizeof(buf) )
			terror("Writing to file\n");
		else	n += sizeof(buf);
	}

	sfsync(sfstdout);

	if(sfopen(sfstdin, tstfile(0),"r") != sfstdin)
		terror("Opening file2\n");
	sfsetbuf(sfstdin,NIL(char*),8*sizeof(buf));
	if(sfsize(sfstdin) != n)
		terror("Wrong size for file\n");

	i = 0;
	for(;;)
	{	if(!(s = sfreserve(sfstdin,16*sizeof(buf),0)) )
			break;
		else	i += 16*sizeof(buf);
	}
	if(sfvalue(sfstdin) > 0)
		i += sfvalue(sfstdin);
	if(i != n)
		terror("Did not read data\n");

	if(sfseek(sfstdin,(Sfoff_t)0,0) != 0)
		terror("sfseek failed0\n");
	sfsetbuf(sfstdin,bigbuf,sizeof(bigbuf));
	i = 0;
	for(;;)
	{	if(!(s = sfreserve(sfstdin,16*sizeof(buf),0)) )
			break;
		else	i += 16*sizeof(buf);
	}
	if(sfvalue(sfstdin) > 0)
		i += sfvalue(sfstdin);
	if(i != n)
		terror("Did not read data2\n");
	sfsetbuf(sfstdin,NIL(Void_t*),(size_t)SF_UNBOUND);

	if(sfopen(sfstdout, tstfile(0), "w") != sfstdout)
		terror("Can't open to write\n");
	for(i = 0; i < 32; ++i)
	{	for(k = 0; k < sizeof(bigbuf); ++k)
			bigbuf[k] = '0' + (k+i)%10;
		if(sfwrite(sfstdout,bigbuf,sizeof(bigbuf)) != sizeof(bigbuf))
			terror("Writing to %s\n", tstfile(0));
	}
	sfclose(sfstdout);

	if(sfopen(sfstdin, tstfile(0), "r") != sfstdin)
		terror("Opening to read\n");
	sfsetbuf(sfstdin,NIL(Void_t*),8*1024);
	if(!(s = sfreserve(sfstdin,16*sizeof(bigbuf),0)) )
		terror("sfreserve failed\n");
	for(i = 0; i < 16; ++i)
	{	for(k = 0; k < sizeof(bigbuf); ++k)
			if(*s++ != ('0' + (k+i)%10))
				terror("Wrong data i=%d k=%d\n",i,k);
	}
	if((o = sfseek(sfstdin,-15*((Sfoff_t)sizeof(bigbuf)),1)) != sizeof(bigbuf))
		terror("sfseek failed o=%lld\n", (Sflong_t)o);
	if(sfread(sfstdin,bigbuf,sizeof(bigbuf)) != sizeof(bigbuf) )
		terror("sfread failed\n");
	s = bigbuf;
	for(i = 1; i < 2; ++i)
	{	for(k = 0; k < sizeof(bigbuf); ++k)
			if(*s++ != ('0' + (k+i)%10))
				terror("Wrong data2 i=%d k=%d\n",i,k);
	}
	if(!(s = sfreserve(sfstdin,16*sizeof(bigbuf),1)) )
	{	sfsetbuf(sfstdin,NIL(Void_t*),16*sizeof(bigbuf));
		if(!(s = sfreserve(sfstdin,16*sizeof(bigbuf),1)) )
			terror("sfreserve failed2\n");
	}
Beispiel #9
0
MAIN()
{
	Sfio_t*	f;
	char	buf[8*1024];
	int	i;
	Sfoff_t	s;

	/* test file resizing */
#if _lib_ftruncate
	if(!(f = sfopen(NIL(Sfio_t*), tstfile(0), "w")) )
		terror("Can't open file %s", tstfile(0));

	for(i = 0; i < sizeof(buf); ++i)
		buf[i] = '1';

	for(i = 0; i < 1024; ++i)
		if(sfwrite(f, buf, sizeof(buf)) != sizeof(buf) )
			terror("Can't write data");

	if(sfclose(f) < 0)
		terror("Can't sync/close file");
	if(!(f = sfopen(NIL(Sfio_t*), tstfile(0), "r+")) )
		terror("Can't open file %s again", tstfile(0));
	if(sfsize(f) != (s = 1024*sizeof(buf)) )
		terror("Bad file size");

	if(sfresize(f, s + sizeof(buf)) < 0)
		terror("Can't resize file");
	if(sfsize(f) != s+sizeof(buf))
		terror("Bad file size");

	sfseek(f, s, 0);
	if(sfread(f,buf,sizeof(buf)) != sizeof(buf))
		terror("Can't read data");

	for(i = 0; i < sizeof(buf); ++i)
		if(buf[i] != 0)
			terror("Bad data");
	sfclose(f);

	if(!(f = sfopen(NIL(Sfio_t*), tstfile(0), "r+")) )
		terror("Can't open file %s again", tstfile(0));
	if(sfsize(f) != s+sizeof(buf))
		terror("Bad file size");

	if(sfresize(f, s) < 0)
		terror("Can't resize file");
	sfclose(f);

	if(!(f = sfopen(NIL(Sfio_t*), tstfile(0), "r+")) )
		terror("Can't open file %s again", tstfile(0));
	if(sfsize(f) != s)
		terror("Bad file size");
#endif

	/* test resizing string stream */
	if(!(f = sfopen(NIL(Sfio_t*),  NIL(char*), "rws")) )
		terror("Can't open string stream");

	for(i = 0; i < sizeof(buf); ++i)
		buf[i] = '1';

	for(i = 0; i < 1024; ++i)
		if(sfwrite(f, buf, sizeof(buf)) != sizeof(buf) )
			terror("Can't write data");

	if(sfsize(f) != (s = 1024*sizeof(buf)) )
		terror("Bad stream size");

	if(sfresize(f, s + sizeof(buf)) < 0)
		terror("Can't resize stream");
	if(sfsize(f) != s+sizeof(buf))
		terror("Bad stream size");

	if(sfseek(f, s, 0) != s)
		terror("seek failed");
	if(sfread(f,buf,sizeof(buf)) != sizeof(buf))
		terror("Can't read data");

	for(i = 0; i < sizeof(buf); ++i)
		if(buf[i] != 0)
			terror("Bad data");

	if(sfresize(f, s) < 0)
		terror("Can't resize stream");
	if(sfsize(f) != s)
		terror("Bad stream size");

	TSTEXIT(0);
}
Beispiel #10
0
Datei: tsize.c Projekt: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    Sfio_t *f, *f2;
    char *s;
    int i, n;
    char buf[16 * 1024];

    if (!(f = sfopen(NULL, tstfile("sf", 0), "w+"))) terror("Can't open file");

    if (sfnputc(f, 'a', 1000) != 1000) terror("Writing");

    if (sfseek(f, (Sfoff_t)0, 0) != 0) terror("Seeking");

    if ((n = (int)sfsize(f)) != 1000) terror("Wrong size %d", n);

    if (!(f2 = sfnew(NULL, NULL, (size_t)SF_UNBOUND, sffileno(f), SF_WRITE))) {
        terror("Can't open stream");
    }

    if (sfseek(f2, (Sfoff_t)1999, 0) != (Sfoff_t)1999) terror("Seeking2");
    sfputc(f2, 'b');
    sfsync(f2);
    if ((n = (int)sfsize(f2)) != 2000) terror("Wrong size2 %d", n);

    if ((n = (int)sfsize(f)) != 1000) terror("Wrong size3 %d", n);

    sfputc(f, 'a');
    sfset(f, SF_SHARE, 1);
    if ((n = (int)sfsize(f)) != 2000) terror("Wrong size4 %d", n);

    if (!(f = sfopen(f, NULL, "srw"))) terror("Can't open string stream");

    sfwrite(f, "0123456789", 10);
    if (sfsize(f) != 10) terror("String size is wrong1");
    sfseek(f, (Sfoff_t)19, 0);
    if (sfsize(f) != 10) terror("String size is wrong2");
    sfputc(f, 'a');
    if (sfsize(f) != 20) terror("String size is wrong3");
    sfseek(f, (Sfoff_t)0, 0);
    if (sfsize(f) != 20) terror("String size is wrong4");
    sfseek(f, (Sfoff_t)0, 0);
    if (!(s = sfreserve(f, SF_UNBOUND, SF_LOCKR)) && sfvalue(f) != 20) {
        terror("String size is wrong5");
    }
    sfread(f, s, 5);
    if (sfsize(f) != 20) terror("String size is wrong6");
    sfwrite(f, "01234567890123456789", 20);
    if (sfsize(f) != 25) terror("String size is wrong7");

    strcpy(buf, "0123456789");
    if (!(f = sfopen(f, buf, "s+"))) terror("Can't open string stream2");
    if (sfset(f, 0, 0) & SF_MALLOC) terror("SF_MALLOC should not have been set");
    if (sfsize(f) != 10) terror("String size is wrong8");
    sfread(f, buf, 5);
    if ((n = (int)sfwrite(f, "0123456789", 10)) != 5) terror("Write wrong amount %d", n);
    if (sfsize(f) != 10) terror("String size is wrong9");

    if (!(f = sfopen(f, tstfile("sf", 0), "w"))) terror("Reopening file1");
    for (i = 0; i < 10000; ++i) {
        if (sfputc(f, '0' + (i % 10)) != '0' + (i % 10)) terror("sfputc failed");
    }

    if (!(f = sfopen(f, tstfile("sf", 0), "r+"))) terror("Reopening file2");
    if (sfsize(f) != 10000) terror("Bad size of file1");

    sfsetbuf(f, buf, 1024);
    for (i = 0; i < 20; ++i) {
        if (!sfreserve(f, 100, 0)) terror("Reserve failed");
    }

    s = buf + 1024;
    for (i = 0; i < 20; ++i) s[i] = '0' + i % 10;
    sfseek(f, (Sfoff_t)(10000 - 10), 0);
    if (sfwrite(f, s, 20) != 20) terror("Write failed");
    if (sfsize(f) != 10010) terror("Bad size of file2");
    sfseek(f, (Sfoff_t)0, 0);
    for (i = 0; i < 10; ++i) {
        if (!(s = sfreserve(f, 1001, 0))) terror("Reserve failed2");
        if (s[0] != '0' + i) terror("Bad data1");
    }
    for (n = 0; n < 1001; ++n) {
        if (s[n] != ((n + i - 1) % 10 + '0')) terror("Bad data");
    }

    /* test to see if a string stream extends ok during writes */
    s = malloc(5);
    f = sfnew(NULL, (void *)s, 5, -1, SF_STRING | SF_READ | SF_WRITE | SF_MALLOC);
    if (!f) terror("Can't create string stream");
    if (sfwrite(f, "01", 2) != 2) terror("Bad write to string stream");
    if (sfwrite(f, "2345678", 7) != 7) terror("Bad write to string stream2");
    if (sfputc(f, 0) != 0) terror("sfputc failed");
    if (sfseek(f, (Sfoff_t)0, 0) != 0) terror("sfseek failed");
    if ((n = (int)sfread(f, buf, 100)) != 10) terror("sfread gets wrong amount of data %d", n);
    if (strcmp(buf, "012345678") != 0) terror("Get wrong data");

    texit(0);
}