1 /*
2 *
3 * Copyright (C) Bull S.A. 2001
4 * Copyright (c) International Business Machines Corp., 2001
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /*
22 * NAME
23 * readv03.c
24 *
25 * DESCRIPTION
26 * Testcase to check the error condition of the readv(2) system call
27 * when fd refers to a directory.
28 *
29 * CALLS
30 * readv()
31 *
32 * ALGORITHM
33 * loop if that option was specified
34 * call readv() when fd refers to a directory.
35 * check the errno value
36 * issue a PASS message if we get EISDIR - errno 21
37 * otherwise, the tests fails
38 * issue a FAIL message
39 * call cleanup
40 *
41 * USAGE$
42 * readv03
43 *
44 * HISTORY
45 * 05/2002 Ported by Jacky Malcles
46 *
47 * RESTRICTIONS
48 * None
49 */
50 #include <sys/types.h>
51 #include <sys/uio.h>
52 #include <sys/fcntl.h>
53 #include <errno.h>
54 #include <string.h>
55 #include <sys/stat.h>
56
57 #include "test.h"
58
59 #define K_1 1024
60 #define MODES S_IRWXU
61
62 char buf1[K_1];
63
64 struct iovec rd_iovec[1] = {
65 {buf1, K_1}
66 };
67
68 const char *TEST_DIR = "alpha";
69 int r_val;
70 int fd;
71
72 char *TCID = "readv03";
73 int TST_TOTAL = 1;
74
75 void setup();
76 void cleanup();
77
main(int ac,char ** av)78 int main(int ac, char **av)
79 {
80 int lc;
81
82 tst_parse_opts(ac, av, NULL, NULL);
83
84 setup();
85
86 /* The following loop checks looping state if -i option given */
87 for (lc = 0; TEST_LOOPING(lc); lc++) {
88
89 /* reset tst_count in case we are looping */
90 tst_count = 0;
91
92 if (readv(fd, rd_iovec, 1) < 0) {
93 if (errno != EISDIR) {
94 tst_resm(TFAIL, "expected errno = EISDIR, "
95 "got %d", errno);
96 } else {
97 tst_resm(TPASS, "got EISDIR");
98 }
99 } else {
100 tst_resm(TFAIL, "Error: readv returned a positive "
101 "value");
102 }
103
104 }
105 cleanup();
106 tst_exit();
107
108 }
109
110 /*
111 * setup() - performs all ONE TIME setup for this test.
112 */
setup(void)113 void setup(void)
114 {
115
116 tst_sig(NOFORK, DEF_HANDLER, cleanup);
117
118 TEST_PAUSE;
119
120 /* make a temporary directory and cd to it */
121 tst_tmpdir();
122
123 /*
124 * create a new directory and open it
125 */
126
127 if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
128 tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
129 "failed", TCID);
130 }
131
132 if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
133 tst_brkm(TBROK, cleanup, "open of directory failed");
134 }
135
136 }
137
138 /*
139 * cleanup() - performs all ONE TIME cleanup for this test at
140 * completion or premature exit.
141 */
cleanup(void)142 void cleanup(void)
143 {
144 if (close(fd) < 0) {
145 tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno);
146 }
147 tst_rmdir();
148
149 }
150