Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/features/peek.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-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
* David Korn <[email protected]> *
19
* Eduardo Krell <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
#include <sys/types.h>
25
26
#if _stream_peek
27
#include <ast_tty.h>
28
#include <stropts.h>
29
#endif
30
31
#if _socket_peek
32
#include <sys/socket.h>
33
#endif
34
35
int
36
main()
37
{
38
int fds[2];
39
static char msg[] = "test";
40
#if _stream_peek
41
struct strpeek pk;
42
#endif
43
44
if (pipe(fds) || write(fds[1], msg, sizeof(msg)) != sizeof(msg))
45
return(0);
46
#if _stream_peek
47
pk.flags = 0;
48
pk.ctlbuf.maxlen = -1;
49
pk.ctlbuf.len = 0;
50
pk.ctlbuf.buf = 0;
51
pk.databuf.maxlen = sizeof(msg);
52
pk.databuf.buf = msg;
53
pk.databuf.len = 0;
54
if (ioctl(fds[0], I_PEEK, &pk) > 0 && pk.databuf.len == sizeof(msg))
55
{
56
printf("#undef _socket_peek\n");
57
return(0);
58
}
59
#endif
60
#if _socket_peek
61
if (recv(fds[0], msg, sizeof(msg), MSG_PEEK) == sizeof(msg))
62
{
63
printf("#undef _stream_peek\n");
64
return(0);
65
}
66
#endif
67
return(0);
68
}
69
70