/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#if _PACKAGE_ast
#include "sftest.h"
#include <stdio.h>
#else
#include "sftest.h"
#endif
/* test compliance of certain stdio behaviors */
tmain()
{
int i, k, fd;
if(argc > 1)
terror("Can't write to stdout");
return 0;
}
/* test for shared streams and seek behavior */
terror("Opening file to read&write");
/* change stdout to a dup of fileno(f) */
/* write something to the dup file descriptor */
/* change stdout back */
/* this fseek should reset the stream back to where we can read */
/* see if data is any good */
for(i = 0; i < 10; ++i)
if(buf[i] != '0'+i)
terror("Bad data0");
/* construct a bunch of lines and out put to f */
for(k = 0; k < sizeof(buf)/10; ++k)
{ for(i = 0; i < 9; ++i)
*sp++ = '0' + i;
*sp++ = '\n';
}
/* write out a bunch of thing */
terror("Writing data");
terror("Can't dup file descriptor");
terror("Can't create stream");
/* read a few bytes from this dup stream */
rbuf[0] = 0;
terror("Bad read");
for(i = 0; i < 7; ++i)
if(rbuf[i] != '0'+i)
terror("Bad data1");
terror("Bad tell location in f2");
/* now seek way off on f */
rbuf[0] = 0;
for(i = 5; i < 9; ++i)
terror("Bad data2");
terror("Bad data: did not get new-line");
if(fputc('x',f) < 0)
terror("fputc failed");
if(fflush(f) < 0)
terror("fflush failed");
if(rbuf[0] != 'x')
terror("Didn't get x");
for(i = 1; i < 9; ++i)
if(rbuf[i] != '0'+i)
terror("Bad data3");
if(rbuf[i] != '\n')
terror("Did not get new-line");
texit(0);
}