Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tmove.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "sftest.h"
21
22
tmain()
23
{
24
char *s = "1234567890\n";
25
Sfoff_t n, i;
26
Sfio_t *f;
27
char buf[1024];
28
char* addr;
29
30
if(sfopen(sfstdout,tstfile("sf", 0),"w+") != sfstdout)
31
terror("Opening output file");
32
for(i = 0; i < 10000; ++i)
33
if(sfputr(sfstdout,s,-1) < 0)
34
terror("Writing data");
35
36
if(!(f = sfopen((Sfio_t*)0,tstfile("sf", 1),"w")))
37
terror("Opening output file ");
38
39
sfseek(sfstdout,(Sfoff_t)0,0);
40
if((n = sfmove(sfstdout,f,(Sfoff_t)SF_UNBOUND,'\n')) != i)
41
terror("Move %d lines, Expect %d",n,i);
42
43
sfseek(sfstdout,(Sfoff_t)0,0);
44
sfseek(f,(Sfoff_t)0,0);
45
sfsetbuf(sfstdout,buf,sizeof(buf));
46
if((n = sfmove(sfstdout,f,(Sfoff_t)SF_UNBOUND,'\n')) != i)
47
terror("Move %d lines, Expect %d",n,i);
48
49
sfopen(sfstdin,tstfile("sf", 0),"r");
50
sfopen(sfstdout,tstfile("sf", 1),"w");
51
sfmove(sfstdin,sfstdout,(Sfoff_t)SF_UNBOUND,-1);
52
if(!sfeof(sfstdin))
53
terror("Sfstdin is not eof");
54
if(sferror(sfstdin))
55
terror("Sfstdin is in error");
56
if(sferror(sfstdout))
57
terror("Sfstdout is in error");
58
59
sfseek(sfstdin,(Sfoff_t)0,0);
60
sfseek(sfstdout,(Sfoff_t)0,0);
61
sfsetbuf(sfstdin,buf,sizeof(buf));
62
63
addr = (char*)sbrk(0);
64
sfmove(sfstdin,sfstdout,(Sfoff_t)((unsigned long)(~0L)>>1),-1);
65
if((ssize_t)((char*)sbrk(0)-addr) > 256*1024)
66
terror("Too much space allocated in sfmove");
67
68
if(!sfeof(sfstdin))
69
terror("Sfstdin is not eof2");
70
if(sferror(sfstdin))
71
terror("Sfstdin is in error2");
72
if(sferror(sfstdout))
73
terror("Sfstdout is in error2");
74
75
texit(0);
76
}
77
78