1*433d6423SLionel Sambuc /* t40g.c
2*433d6423SLionel Sambuc *
3*433d6423SLionel Sambuc * Test select on character driver that does not support select
4*433d6423SLionel Sambuc *
5*433d6423SLionel Sambuc * We use /dev/zero for this right now. If the memory driver ever implements
6*433d6423SLionel Sambuc * select support, this test should be changed to use another character driver.
7*433d6423SLionel Sambuc */
8*433d6423SLionel Sambuc
9*433d6423SLionel Sambuc #include <stdio.h>
10*433d6423SLionel Sambuc #include <stdlib.h>
11*433d6423SLionel Sambuc #include <unistd.h>
12*433d6423SLionel Sambuc #include <sys/types.h>
13*433d6423SLionel Sambuc #include <sys/select.h>
14*433d6423SLionel Sambuc #include <sys/wait.h>
15*433d6423SLionel Sambuc #include <sys/time.h>
16*433d6423SLionel Sambuc #include <time.h>
17*433d6423SLionel Sambuc #include <errno.h>
18*433d6423SLionel Sambuc #include <string.h>
19*433d6423SLionel Sambuc #include <signal.h>
20*433d6423SLionel Sambuc #include <fcntl.h>
21*433d6423SLionel Sambuc
22*433d6423SLionel Sambuc #include "common.h"
23*433d6423SLionel Sambuc
24*433d6423SLionel Sambuc int
main(int argc,char ** argv)25*433d6423SLionel Sambuc main(int argc, char **argv)
26*433d6423SLionel Sambuc {
27*433d6423SLionel Sambuc fd_set set;
28*433d6423SLionel Sambuc int fd, retval;
29*433d6423SLionel Sambuc
30*433d6423SLionel Sambuc /* Get subtest number */
31*433d6423SLionel Sambuc if (argc != 2 || sscanf(argv[1], "%d", &subtest) != 1) {
32*433d6423SLionel Sambuc printf("Usage: %s subtest_no\n", argv[0]);
33*433d6423SLionel Sambuc exit(-2);
34*433d6423SLionel Sambuc }
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc /*
37*433d6423SLionel Sambuc * Do a select on /dev/zero, with the expectation that it will fail
38*433d6423SLionel Sambuc * with an EBADF error code.
39*433d6423SLionel Sambuc */
40*433d6423SLionel Sambuc fd = open("/dev/zero", O_RDONLY);
41*433d6423SLionel Sambuc if (fd < 0) em(1, "unable to open /dev/zero");
42*433d6423SLionel Sambuc
43*433d6423SLionel Sambuc FD_ZERO(&set);
44*433d6423SLionel Sambuc FD_SET(fd, &set);
45*433d6423SLionel Sambuc
46*433d6423SLionel Sambuc retval = select(fd + 1, &set, NULL, NULL, NULL);
47*433d6423SLionel Sambuc if (retval != -1) em(2, "select call was expected to fail");
48*433d6423SLionel Sambuc if (errno != EBADF) em(3, "error code other than EBADF returned");
49*433d6423SLionel Sambuc if (!FD_ISSET(fd, &set)) em(4, "file descriptor set was modified");
50*433d6423SLionel Sambuc
51*433d6423SLionel Sambuc exit(errct);
52*433d6423SLionel Sambuc }
53