Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/talign.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
static ssize_t Read;
23
static int Count;
24
25
#if __STD_C
26
ssize_t readf(Sfio_t* f, Void_t* buf, size_t n, Sfdisc_t* disc)
27
#else
28
ssize_t readf(f,buf,n,disc)
29
Sfio_t* f;
30
Void_t* buf;
31
size_t n;
32
Sfdisc_t* disc;
33
#endif
34
{
35
Count += 1;
36
Read += (n = sfrd(f,buf,n,disc));
37
return n;
38
}
39
40
Sfdisc_t Disc = {readf, (Sfwrite_f)0, (Sfseek_f)0, (Sfexcept_f)0, (Sfdisc_t*)0};
41
42
tmain()
43
{
44
Sfio_t* f;
45
int i;
46
char* s;
47
char buf[1024], rbuf[128*1024];
48
49
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w")) )
50
terror("Opening to write");
51
52
for(i = 0; i < sizeof(buf); ++i)
53
buf[i] = 'a' + (i%26);
54
55
for(i = 0; i < 1024; ++i)
56
if(sfwrite(f,buf,sizeof(buf)) != sizeof(buf) )
57
terror("Write error");
58
sfclose(f);
59
60
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "r")) )
61
terror("Opening to read");
62
sfsetbuf(f,rbuf,sizeof(rbuf));
63
64
sfdisc(f,&Disc);
65
66
for(i = 0;; i += 64)
67
{ sfseek(f,(Sfoff_t)i,0);
68
if(!(s = sfreserve(f,619,SF_LOCKR)) )
69
break;
70
sfread(f,s,64);
71
}
72
73
if(Read != 1024*sizeof(buf) )
74
terror("Count=%d Read=%d", Count, Read);
75
76
texit(0);
77
}
78
79