readv03.c revision 1569799abe4296fc5ca50ede305c1eb2ac482422
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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#include "usctest.h" 59 60#define K_1 1024 61#define MODES S_IRWXU 62 63char buf1[K_1]; 64 65struct iovec rd_iovec[1] = { 66 {buf1, K_1} 67}; 68 69const char *TEST_DIR = "alpha"; 70int r_val; 71int fd; 72 73char *TCID = "readv03"; 74int TST_TOTAL = 1; 75 76void setup(); 77void cleanup(); 78 79int main(int ac, char **av) 80{ 81 int lc; /* loop counter */ 82 char *msg; /* message returned from parse_opts */ 83 84 /* parse standard options */ 85 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { 86 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 87 } 88 89 setup(); 90 91 /* The following loop checks looping state if -i option given */ 92 for (lc = 0; TEST_LOOPING(lc); lc++) { 93 94 /* reset Tst_count in case we are looping */ 95 Tst_count = 0; 96 97 if (readv(fd, rd_iovec, 1) < 0) { 98 if (errno != EISDIR) { 99 tst_resm(TFAIL, "expected errno = EISDIR, " 100 "got %d", errno); 101 } else { 102 tst_resm(TPASS, "got EISDIR"); 103 } 104 } else { 105 tst_resm(TFAIL, "Error: readv returned a positive " 106 "value"); 107 } 108 109 } 110 cleanup(); 111 112} 113 114/* 115 * setup() - performs all ONE TIME setup for this test. 116 */ 117void setup() 118{ 119 120 tst_sig(NOFORK, DEF_HANDLER, cleanup); 121 122 TEST_PAUSE; 123 124 /* make a temporary directory and cd to it */ 125 tst_tmpdir(); 126 127 /* 128 * create a new directory and open it 129 */ 130 131 if ((r_val = mkdir(TEST_DIR, MODES)) == -1) { 132 tst_brkm(TBROK, cleanup, "%s - mkdir() in main() " 133 "failed", TCID); 134 } 135 136 if ((fd = open(TEST_DIR, O_RDONLY)) == -1) { 137 tst_brkm(TBROK, cleanup, "open of directory failed"); 138 } 139 140} 141 142/* 143 * cleanup() - performs all ONE TIME cleanup for this test at 144 * completion or premature exit. 145 */ 146void cleanup() 147{ 148 if (close(fd) < 0) { 149 tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno); 150 } 151 tst_rmdir(); 152 153}