1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * NAME
22 * close02.c
23 *
24 * DESCRIPTION
25 * Check that an invalid file descriptor returns EBADF
26 *
27 * ALGORITHM
28 * loop if that option is specified
29 * call close using the TEST macro and passing in an invalid fd
30 * if the call succeedes
31 * issue a FAIL message
32 * else
33 * log the errno
34 * if the errno == EBADF
35 * issue a PASS message
36 * else
37 * issue a FAIL message
38 * cleanup
39 *
40 * USAGE: <for command-line>
41 * close02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
42 * where, -c n : Run n copies concurrently.
43 * -e : Turn on errno logging.
44 * -i n : Execute test n times.
45 * -I x : Execute test for x seconds.
46 * -P x : Pause for x seconds between iterations.
47 * -t : Turn on syscall timing.
48 *
49 * HISTORY
50 * 07/2001 Ported by Wayne Boyer
51 *
52 * RESTRICTIONS
53 * None
54 */
55
56 #include <stdio.h>
57 #include <errno.h>
58 #include <sys/stat.h>
59 #include "test.h"
60
61 void cleanup(void);
62 void setup(void);
63
64 char *TCID = "close02";
65 int TST_TOTAL = 1;
66
main(int ac,char ** av)67 int main(int ac, char **av)
68 {
69 int lc;
70
71 tst_parse_opts(ac, av, NULL, NULL);
72
73 setup();
74
75 /* The following loop checks looping state if -i option given */
76 for (lc = 0; TEST_LOOPING(lc); lc++) {
77
78 /* reset tst_count in case we are looping */
79 tst_count = 0;
80
81 TEST(close(-1));
82
83 if (TEST_RETURN != -1) {
84 tst_resm(TFAIL, "Closed a non existent fildes");
85 } else {
86 if (TEST_ERRNO != EBADF) {
87 tst_resm(TFAIL, "close() FAILED to set errno "
88 "to EBADF on an invalid fd, got %d",
89 errno);
90 } else {
91 tst_resm(TPASS, "call returned EBADF");
92 }
93 }
94 }
95 cleanup();
96
97 tst_exit();
98
99 }
100
101 /*
102 * setup() - performs all ONE TIME setup for this test
103 */
setup(void)104 void setup(void)
105 {
106
107 tst_sig(FORK, DEF_HANDLER, cleanup);
108
109 umask(0);
110
111 TEST_PAUSE;
112 }
113
114 /*
115 * cleanup() - performs all the ONE TIME cleanup for this test at completion
116 * or premature exit.
117 */
cleanup(void)118 void cleanup(void)
119 {
120
121 }
122