tresize.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* 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> *
* *
***********************************************************************/
#include "sftest.h"
tmain()
{
Sfio_t* f;
int i;
Sfoff_t s;
/* test file resizing */
#if _lib_ftruncate
for(i = 0; i < sizeof(buf); ++i)
buf[i] = '1';
for(i = 0; i < 1024; ++i)
terror("Can't write data");
if(sfclose(f) < 0)
terror("Bad file size");
terror("Can't resize file");
terror("Bad file size");
sfseek(f, s, 0);
terror("Can't read data");
for(i = 0; i < sizeof(buf); ++i)
if(buf[i] != 0)
terror("Bad data");
sfclose(f);
terror("Bad file size");
if(sfresize(f, s) < 0)
terror("Can't resize file");
sfclose(f);
if(sfsize(f) != s)
terror("Bad file size");
#endif
/* test resizing string stream */
terror("Can't open string stream");
for(i = 0; i < sizeof(buf); ++i)
buf[i] = '1';
for(i = 0; i < 1024; ++i)
terror("Can't write data");
terror("Bad stream size");
terror("Can't resize stream");
terror("Bad stream size");
if(sfseek(f, s, 0) != s)
terror("seek failed");
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");
texit(0);
}