head 1.3; access; symbols SFIO_1999:1.1.1.3 SFIO_1998:1.1.1.2 SFIO_1997:1.1.1.1 ATT:1.1.1; locks; strict; comment @ * @; 1.3 date 99.09.11.13.20.43; author rse; state Exp; branches; next 1.2; 1.2 date 99.09.11.12.42.11; author rse; state Exp; branches; next 1.1; 1.1 date 96.10.04.20.21.28; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 96.10.04.20.21.28; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 98.04.05.15.14.09; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 99.06.04.19.05.42; author rse; state Exp; branches; next ; desc @@ 1.3 log @Merge in Sfio 1999 changes @ text @#include "sftest.h" static char Serial[128], *S = Serial; #if __STD_C static ssize_t writef(Sfio_t* f, const Void_t* buf, size_t n, Sfdisc_t* disc) #else static ssize_t writef(f, buf, n, disc) Sfio_t* f; Void_t* buf; size_t n; Sfdisc_t* disc; #endif { memcpy((Void_t*)S,buf,n); S += n; return n; } Sfdisc_t Serialdc = {NIL(Sfread_f), writef, NIL(Sfseek_f), NIL(Sfexcept_f) }; int main() { int i, n = 0, on; char *s, *os; char poolbuf[1024]; Sfio_t *f1, *f2 = NULL, *f3 = NULL, *f4; if(!(f1 = sfopen((Sfio_t*)0,Kpv[0],"w+")) || !(f2 = sfopen((Sfio_t*)0,Kpv[1],"w")) || !(f3 = sfopen((Sfio_t*)0,Kpv[2],"w"))) terror("Opening files\n"); if(!(f4 = sfopen((Sfio_t*)0,Kpv[0],"r+")) ) terror("Opening file to read\n"); sfungetc(f1,'a'); sfungetc(f4,'b'); sfpool(f1,f4,0); sfungetc(f1,'a'); sfpool(f1,NIL(Sfio_t*),0); sfsetbuf(f2,poolbuf,sizeof(poolbuf)); sfsetbuf(f3,poolbuf,sizeof(poolbuf)); if(!sfpool(f2,f3,0) ) terror("Setting pool\n"); os = "1234567890\n"; on = strlen(os); for(i = 0; i < 100; ++i) if(sfputr(f1,os,-1) < 0) terror("Writing data\n"); sfseek(f1,(Sfoff_t)0,0); for(i = 0; i < 100; ++i) { if(!(s = sfgetr(f1,'\n',1)) || (n = sfvalue(f1)) != on) terror("Reading data\n"); if(sfwrite(f2,s,n) != n) terror("Writing1\n"); if(sfwrite(f3,s,n) != n) terror("Writing2\n"); } if(sfclose(f1) < 0) terror("Closing file f1\n"); if(sfclose(f2) < 0) terror("Closing file f2\n"); if(sfclose(f3) < 0) terror("Closing file f3\n"); f1 = sfstdout; f2 = sfstderr; sfdisc(sfstdout,&Serialdc); sfdisc(sfstderr,&Serialdc); sfset(sfstdout,SF_LINE,0); sfset(sfstderr,SF_LINE,0); if(sfpool(sfstdout,sfstderr,0) != sfstderr ) terror("sfpool1\n"); sfputc(sfstdout,'1'); sfputc(sfstderr,'2'); sfputc(sfstdout,'3'); sfputc(sfstderr,'4'); sfsync(sfstderr); if(strcmp(Serial,"1234") != 0) terror("Pool not serializing output\n"); sfdisc(sfstdout,NIL(Sfdisc_t*)); sfdisc(sfstderr,NIL(Sfdisc_t*)); sfclose(sfstdout); if(!(f1 = sfopen((Sfio_t*)0,Kpv[0],"r"))) terror("sfopen\n"); if(!sfpool(f1,sfstderr,0) ) terror("sfpool2\n"); s = sfprints("cmp %s %s 2>&1; cmp %s %s 2>&1; rm %s %s %s 2>&1", Kpv[0],Kpv[1], Kpv[1],Kpv[2], Kpv[0],Kpv[1],Kpv[2]); system(s); if(!(f1 = sfopen(NIL(Sfio_t*), Kpv[0], "w+")) || !(f2 = sfopen(NIL(Sfio_t*), Kpv[1], "w+")) || !(f3 = sfopen(NIL(Sfio_t*), Kpv[2], "w+")) ) terror("sfopen3\n"); if(sfpool(f1,f2,SF_SHARE) != f2 || sfpool(f3,f2,SF_SHARE) != f2 ) terror("sfpool3\n"); if(sfputc(f3,'x') < 0) terror("sfputc to f3\n"); if(sfputc(f2,'y') < 0) terror("sfputc to f2\n"); if(sfputc(f1,'z') < 0) terror("sfputc to f1\n"); if(sfseek(f1,(Sfoff_t)0,0) != 0) terror("sfseek failed on f1\n"); if(!(s = sfreserve(f1,3,1)) || sfvalue(f1) != 3) terror("sfreserve failed on f1\n"); if(memcmp(s,"xyz",3) != 0) terror("Wrong data\n"); if((os = sfreserve(f2,-1,0)) ) terror("sfreserve should have failed on f2\n"); if(sfpool(NIL(Sfio_t*),f2,0) != f1) terror("Didn't get right pool head for f2\n"); if(sfread(f1,s,3) != 3) terror("Wrong read on f1\n"); if(!sfpool(f3,NIL(Sfio_t*),0) ) terror("sfpool to delete f3\n"); if(sfpool(f1,NIL(Sfio_t*),0) != f2 ) terror("sfpool to delete f1\n"); if(!(f1 = sfopen(NIL(Sfio_t*), Kpv[0], "w+")) || !(f2 = sfopen(NIL(Sfio_t*), Kpv[1], "w")) ) terror("sfopen4\n"); sfputc(f1,'a'); sfputc(f1,'b'); sfputc(f1,'c'); sfset(f1,SF_WRITE,0); /* off write mode */ if(sfpool(f1,f2,SF_SHARE) ) terror("sfpool should fail pooling read+write streams\n"); if(sfseek(f1,(Sfoff_t)0,0) != (Sfoff_t)0) terror("sfseek failed\n"); if(!(s = sfreserve(f1,3,1)) || memcmp(s,"abc",3) != 0) terror("Can't get data from f1\n"); rmkpv(); return 0; } @ 1.2 log @Incorporate stuff from RSE's Sfio98 variant @ text @d27 3 a29 3 if(!(f1 = sfopen((Sfio_t*)0,"xxx","w+")) || !(f2 = sfopen((Sfio_t*)0,"yyy","w")) || !(f3 = sfopen((Sfio_t*)0,"zzz","w"))) d32 2 a33 2 if(!(f4 = sfopen((Sfio_t*)0,"xxx","r+")) ) terror("Opening xxx\n"); d55 1 a55 1 terror("Writing to yyy\n"); d57 1 a57 1 terror("Writing to zzz\n"); d84 1 a84 1 if(!(f1 = sfopen((Sfio_t*)0,"xxx","r"))) d89 7 a95 5 system("cmp xxx yyy 2>&1; cmp yyy zzz 2>&1; rm xxx yyy zzz"); if(!(f1 = sfopen(NIL(Sfio_t*), "xxx", "w+")) || !(f2 = sfopen(NIL(Sfio_t*), "yyy", "w+")) || !(f3 = sfopen(NIL(Sfio_t*), "zzz", "w+")) ) d127 2 a128 2 if(!(f1 = sfopen(NIL(Sfio_t*), "xxx", "w+")) || !(f2 = sfopen(NIL(Sfio_t*), "yyy", "w")) ) d141 1 a141 2 system("rm xxx yyy zzz"); @ 1.1 log @Initial revision @ text @d5 1 a5 1 ssize_t writef(Sfio_t* f, const Void_t* buf, size_t n, Sfdisc_t* disc) d7 1 a7 1 ssize_t writef(f, buf, n, disc) d20 1 a20 1 main() d22 1 a22 1 int i, n, on; d25 1 a25 1 Sfio_t *f1, *f2, *f3, *f4; d59 6 a64 2 if(sfclose(f1) < 0 || sfclose(f2) < 0 || sfclose(f3) < 0) terror("Closing files\n"); d66 1 d71 1 a71 1 if(!sfpool(sfstdout,sfstderr,0) ) d91 3 a93 3 if(!(f1 = sfopen(NIL(Sfio_t*),NIL(char*),"s+")) || !(f2 = sfopen(NIL(Sfio_t*),NIL(char*),"s+")) || !(f3 = sfopen(NIL(Sfio_t*),NIL(char*),"s+")) ) d95 1 a95 1 if(!sfpool(f1,f2,SF_SHARE) || !sfpool(f3,f2,SF_SHARE) ) d97 1 a97 1 if(sfputc(f3,'z') < 0) d99 20 d121 2 a122 3 if(sfputc(f1,'x') < 0) terror("sfputc from f1\n"); if(!sfpool(f1,NIL(Sfio_t*),0) ) d124 16 @ 1.1.1.1 log @Import of Sfio1997 @ text @@ 1.1.1.2 log @Import of Sfio1998 @ text @d59 2 a60 6 if(sfclose(f1) < 0) terror("Closing file f1\n"); if(sfclose(f2) < 0) terror("Closing file f2\n"); if(sfclose(f3) < 0) terror("Closing file f3\n"); a61 1 f1 = sfstdout; f2 = sfstderr; d66 1 a66 1 if(sfpool(sfstdout,sfstderr,0) != sfstderr ) d86 3 a88 3 if(!(f1 = sfopen(NIL(Sfio_t*), "xxx", "w+")) || !(f2 = sfopen(NIL(Sfio_t*), "yyy", "w+")) || !(f3 = sfopen(NIL(Sfio_t*), "zzz", "w+")) ) d90 1 a90 1 if(sfpool(f1,f2,SF_SHARE) != f2 || sfpool(f3,f2,SF_SHARE) != f2 ) d92 1 a92 1 if(sfputc(f3,'x') < 0) a93 20 if(sfputc(f2,'y') < 0) terror("sfputc to f2\n"); if(sfputc(f1,'z') < 0) terror("sfputc to f1\n"); if(sfseek(f1,(Sfoff_t)0,0) != 0) terror("sfseek failed on f1\n"); if(!(s = sfreserve(f1,3,1)) || sfvalue(f1) != 3) terror("sfreserve failed on f1\n"); if(memcmp(s,"xyz",3) != 0) terror("Wrong data\n"); if((os = sfreserve(f2,-1,0)) ) terror("sfreserve should have failed on f2\n"); if(sfpool(NIL(Sfio_t*),f2,0) != f1) terror("Didn't get right pool head for f2\n"); if(sfread(f1,s,3) != 3) terror("Wrong read on f1\n"); d96 3 a98 2 if(sfpool(f1,NIL(Sfio_t*),0) != f2 ) a99 16 if(!(f1 = sfopen(NIL(Sfio_t*), "xxx", "w+")) || !(f2 = sfopen(NIL(Sfio_t*), "yyy", "w")) ) terror("sfopen4\n"); sfputc(f1,'a'); sfputc(f1,'b'); sfputc(f1,'c'); sfset(f1,SF_WRITE,0); /* off write mode */ if(sfpool(f1,f2,SF_SHARE) ) terror("sfpool should fail pooling read+write streams\n"); if(sfseek(f1,(Sfoff_t)0,0) != (Sfoff_t)0) terror("sfseek failed\n"); if(!(s = sfreserve(f1,3,1)) || memcmp(s,"abc",3) != 0) terror("Can't get data from f1\n"); system("rm xxx yyy zzz"); @ 1.1.1.3 log @Import of Sfio1999 @ text @d27 3 a29 3 if(!(f1 = sfopen((Sfio_t*)0,Kpv[0],"w+")) || !(f2 = sfopen((Sfio_t*)0,Kpv[1],"w")) || !(f3 = sfopen((Sfio_t*)0,Kpv[2],"w"))) d32 2 a33 2 if(!(f4 = sfopen((Sfio_t*)0,Kpv[0],"r+")) ) terror("Opening file to read\n"); d55 1 a55 1 terror("Writing1\n"); d57 1 a57 1 terror("Writing2\n"); d84 1 a84 1 if(!(f1 = sfopen((Sfio_t*)0,Kpv[0],"r"))) d89 5 a93 7 s = sfprints("cmp %s %s 2>&1; cmp %s %s 2>&1; rm %s %s %s 2>&1", Kpv[0],Kpv[1], Kpv[1],Kpv[2], Kpv[0],Kpv[1],Kpv[2]); system(s); if(!(f1 = sfopen(NIL(Sfio_t*), Kpv[0], "w+")) || !(f2 = sfopen(NIL(Sfio_t*), Kpv[1], "w+")) || !(f3 = sfopen(NIL(Sfio_t*), Kpv[2], "w+")) ) d125 2 a126 2 if(!(f1 = sfopen(NIL(Sfio_t*), Kpv[0], "w+")) || !(f2 = sfopen(NIL(Sfio_t*), Kpv[1], "w")) ) d139 2 a140 1 rmkpv(); @