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.12; author rse; state Exp; branches; next 1.1; 1.1 date 96.12.13.21.29.00; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 96.12.13.21.29.00; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 98.04.02.16.23.15; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 99.08.04.19.19.51; author rse; state Exp; branches; next ; desc @@ 1.3 log @Merge in Sfio 1999 changes @ text @#include "sftest.h" #undef fork /* make sure fork() is used, not vfork() */ _BEGIN_EXTERNS_ extern int fork(); extern int wait _ARG_((int*)); _END_EXTERNS_ static int Count = 0; static Sfdisc_t Disc; static char Rec[] = "0"; #if __STD_C static void count(Sfio_t* f, int type, int fd) #else static void count(f, type, fd) Sfio_t* f; int type; int fd; #endif { if(fd >= 0) Count += 1; } int main() { Sfio_t* f; char* s; ssize_t siz; Sfoff_t pos; Sfoff_t nxt; int pid; /* ast ed does this */ if (!(f = sftmp(SF_BUFSIZE))) terror("sftmp\n"); if ((pos = sfseek(f, (Sfoff_t)0, SEEK_CUR))) terror("top offset %I*d expected 0\n", sizeof(pos), pos); if ((siz = sfputr(f, Rec, 0)) != sizeof(Rec)) terror("put record size %I*d expected %d\n", sizeof(siz), siz, sizeof(Rec)); if ((nxt = sfseek(f, (Sfoff_t)0, SEEK_CUR)) != (pos + siz)) terror("put record size %I*d offset %I*d expected %I*d\n", sizeof(siz), siz, sizeof(nxt), nxt, sizeof(nxt), nxt + sizeof(Rec)); if ((pos = sfseek(f, (Sfoff_t)SF_BUFSIZE, SEEK_CUR)) != (nxt + SF_BUFSIZE)) terror("skip block size %d offset %I*d expected %I*d\n", SF_BUFSIZE, sizeof(nxt), nxt, sizeof(nxt), nxt + SF_BUFSIZE); sfclose(f); /* let two run concurrently */ if((pid = fork()) < 0) return 0; f = sftmp((size_t)SF_UNBOUND); sfputr(f,"1234",'\n'); /* write a string into it */ sfseek(f,(Sfoff_t)0,0); /* get back so we can read the string */ s = sfreserve(f,-1,0); if(sfvalue(f) != 5) terror("Get n=%d, expect n=5\n", sfvalue(f)); sfseek(f,(Sfoff_t)10,1); /* seek to extend buffer */ if((s = sfreserve(f,-1,0))) terror("Get n=%d, expect n=0\n", sfvalue(f)); sfset(f,SF_READ,0); /* turn off read mode so stream is write only */ sfseek(f,(Sfoff_t)(-10),1); /* back 10 places to get space to write */ if(!(s = sfreserve(f,-1,1)) || sfwrite(f,s,0) != 0) terror("Get n=%d, expect n > 0\n", sfvalue(f)); strcpy(s,"5678\n"); sfset(f,SF_READ,1); sfseek(f,(Sfoff_t)0,0); /* read 1234\n5678\n */ if(!(s = sfreserve(f,-1,1)) || sfread(f,s,0) != 0) terror("Get n=%d, expect n > 0\n", sfvalue(f)); if(strncmp(s,"1234\n5678\n",10) != 0) terror("Get wrong string\n"); sfclose(f); sfnotify(count); if(!(f = sftmp(0)) ) terror("sftmp\n"); if(Count != 1) terror("wrong count 1, count=%d\n", Count); sfclose(f); if(Count != 2) terror("wrong count 2 count=%d\n", Count); if(!(f = sftmp(8)) ) terror("sftmp\n"); if(Count != 2) terror("wrong count 2.2 count=%d\n", Count); sfdisc(f,&Disc); if(Count != 3) terror("wrong count 3 count=%d\n", Count); sfclose(f); if(Count != 4) terror("wrong count 4 count=%d\n", Count); if(!(f = sftmp(8)) ) terror("sftmp\n"); if(Count != 4) terror("wrong count 4.2 count=%d\n", Count); sfwrite(f,"0123456789",10); if(Count != 5) terror("wrong count 5 count=%d\n", Count); sfclose(f); if(Count != 6) terror("wrong count 6 count=%d\n", Count); if(!(f = sftmp(1024)) ) terror("sftmp\n"); sfwrite(f,"1234567890",10); sfseek(f,(Sfoff_t)0,0); if(sfsize(f) != 10) terror("Wrong size\n"); sfdisc(f,SF_POPDISC); if(sfsize(f) != 10) terror("Wrong size\n"); s = sfreserve(f,-1,0); if(sfvalue(f) != 10 || strncmp(s,"1234567890",10) != 0) terror("did not create correct real file\n"); if(pid != 0) wait(&pid); return 0; } @ 1.2 log @Incorporate stuff from RSE's Sfio98 variant @ text @d5 5 d35 1 d55 2 a56 1 fork(); d128 4 @ 1.1 log @Initial revision @ text @d8 2 d11 1 a11 1 void count(Sfio_t* f, int type, int fd) d13 1 a13 1 void count(f, type, fd) d23 1 a23 1 main() d25 22 a46 2 Sfio_t *f; char *s; d60 1 a60 1 if(s = sfreserve(f,-1,0)) d80 1 a80 1 terror("sftmp failed 1\n"); d88 1 a88 1 terror("sftmp failed 2\n"); d99 1 a99 1 terror("sftmp failed 3\n"); d110 1 a110 1 terror("sftmp failed 4\n"); d114 1 a114 1 terror("Wrong size1\n"); d117 1 a117 1 terror("Wrong size2\n"); a120 1 @ 1.1.1.1 log @Import of Sfio1997 @ text @@ 1.1.1.2 log @Import of Sfio1998 @ text @a7 2 static char Rec[] = "0"; d23 2 a24 22 Sfio_t* f; char* s; ssize_t siz; Sfoff_t pos; Sfoff_t nxt; /* ast ed does this */ if (!(f = sftmp(SF_BUFSIZE))) terror("sftmp\n"); if (pos = sfseek(f, (Sfoff_t)0, SEEK_CUR)) terror("top offset %I*d expected 0\n", sizeof(pos), pos); if ((siz = sfputr(f, Rec, 0)) != sizeof(Rec)) terror("put record size %I*d expected %d\n", sizeof(siz), siz, sizeof(Rec)); if ((nxt = sfseek(f, (Sfoff_t)0, SEEK_CUR)) != (pos + siz)) terror("put record size %I*d offset %I*d expected %I*d\n", sizeof(siz), siz, sizeof(nxt), nxt, sizeof(nxt), nxt + sizeof(Rec)); if ((pos = sfseek(f, (Sfoff_t)SF_BUFSIZE, SEEK_CUR)) != (nxt + SF_BUFSIZE)) terror("skip block size %d offset %I*d expected %I*d\n", SF_BUFSIZE, sizeof(nxt), nxt, sizeof(nxt), nxt + SF_BUFSIZE); sfclose(f); d58 1 a58 1 terror("sftmp\n"); d66 1 a66 1 terror("sftmp\n"); d77 1 a77 1 terror("sftmp\n"); d88 1 a88 1 terror("sftmp\n"); d92 1 a92 1 terror("Wrong size\n"); d95 1 a95 1 terror("Wrong size\n"); d99 1 @ 1.1.1.3 log @Import of Sfio1999 @ text @a4 5 _BEGIN_EXTERNS_ extern int fork(); extern int wait _ARG_((int*)); _END_EXTERNS_ a29 1 int pid; d49 1 a49 2 if((pid = fork()) < 0) return 0; a120 4 if(pid != 0) wait(&pid); @