Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tnotify.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 int Type;
23
static int Mttype;
24
25
#if __STD_C
26
static void notify(Sfio_t* f, int type, void* data)
27
#else
28
static void notify(f, type, data)
29
Sfio_t* f;
30
int type;
31
void* data;
32
#endif
33
{
34
switch(type)
35
{
36
case SF_NEW:
37
case SF_CLOSING:
38
case SF_SETFD:
39
case SF_READ:
40
case SF_WRITE:
41
Type = type;
42
return;
43
case SF_MTACCESS:
44
Mttype = type;
45
return;
46
default:
47
terror("Unexpected nofity-type: %d",type);
48
}
49
}
50
51
tmain()
52
{
53
Sfio_t* f;
54
int fd;
55
56
sfnotify(notify);
57
58
if(!(f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w")) && Type != SF_NEW)
59
terror("Notify did not announce SF_NEW event");
60
fd = sffileno(f);
61
close(fd+5);
62
if(sfsetfd(f,fd+5) != fd+5 || Type != SF_SETFD)
63
terror("Notify did not announce SF_SETFD event");
64
if(sfclose(f) < 0 || Type != SF_CLOSING)
65
terror("Notify did not announce SF_CLOSING event");
66
67
if(sfputc(sfstdin,'a') >= 0 || Type != SF_WRITE)
68
terror("Notify did not announce SF_WRITE event");
69
70
if(sfgetc(sfstdout) >= 0 || Type != SF_READ)
71
terror("Notify did not announce SF_READ event");
72
73
texit(0);
74
}
75
76