Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tnoseek.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
char* buffer;
23
size_t size;
24
size_t count;
25
26
#if __STD_C
27
Sfoff_t discseek(Sfio_t* f, Sfoff_t offset, int type, Sfdisc_t* disc)
28
#else
29
Sfoff_t discseek(f,offset,type,disc)
30
Sfio_t* f;
31
Sfoff_t offset;
32
int type;
33
Sfdisc_t* disc;
34
#endif
35
{
36
return 0;
37
}
38
39
#if __STD_C
40
ssize_t discwrite(Sfio_t* f, const Void_t* s, size_t n, Sfdisc_t* disc)
41
#else
42
ssize_t discwrite(f,s,n,disc)
43
Sfio_t* f;
44
Void_t* s;
45
size_t n;
46
Sfdisc_t* disc;
47
#endif
48
{
49
buffer = (char*)s;
50
size = n;
51
count += 1;
52
return n;
53
}
54
55
Sfdisc_t seekable = { (Sfread_f)0, discwrite, discseek, (Sfexcept_f)0 };
56
57
tmain()
58
{
59
char buf[1024];
60
61
sfsetbuf(sfstdout,buf,sizeof(buf));
62
sfset(sfstdout,SF_LINE,0);
63
64
if(sfdisc(sfstdout,&seekable) != &seekable)
65
terror("Can't set discipline");
66
if(sfseek(sfstdout,(Sfoff_t)0,0) < 0)
67
terror("Sfstdout should be seekable");
68
if(sfwrite(sfstdout,"123\n",4) != 4)
69
terror("Can't write");
70
if(sfwrite(sfstdout,"123\n",4) != 4)
71
terror("Can't write");
72
if(sfdisc(sfstdout,NIL(Sfdisc_t*)) != &seekable)
73
terror("Can't pop discipline");
74
75
if(buffer != buf || size != 8 || count != 1)
76
terror("Wrong calls to write");
77
78
texit(0);
79
}
80
81