/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1999-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#include "sftest.h"2021/* This test checks to see if sfread() will always fill the buffer22** from a piped-stream correctly even if the other end of the pipe23** is writing odd amounts of bytes.24*/25#define RBUF 1626#define ITER 10242728tmain()29{30Sfio_t *fr;31int p[2];32char wbuf[1023], rbuf[RBUF*1023], *s;33int i, r, n;3435if(pipe(p) < 0 )36terror("Making pipe for communication");3738if(!(fr = sfnew(0, 0, (size_t)SF_UNBOUND, p[0], SF_READ)) )39terror("Making read stream");4041for(i = 0; i < sizeof(wbuf); ++i)42wbuf[i] = (i%10) + '0';4344switch(fork())45{46case -1 :47terror("fork() failed");48case 0 :49for(i = 0; i < RBUF*ITER; ++i)50if(write(p[1], wbuf, sizeof(wbuf)) != sizeof(wbuf))51terror("Write to pipe failed i=%d", i);52break;53default:54for(i = 0; i < ITER; ++i)55{ if(sfread(fr, rbuf, sizeof(rbuf)) != sizeof(rbuf))56terror("Read from pipe failed i=%d", i);57for(r = 0, s = rbuf; r < RBUF; r += 1, s += n)58for(n = 0; n < sizeof(wbuf); ++n)59if(s[n] != (n%10)+'0')60terror("Bad data i=%d n=%d", i, n);61}62break;63}6465texit(0);66}676869