1 /* 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 3 * Copyright (c) 2011 Cyril Hrubis <chrubis (at) suse.cz> 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * 13 * Further, this software is distributed without any warranty that it is 14 * free of the rightful claim of any third person regarding infringement 15 * or the like. Any license provided herein, whether implied or 16 * otherwise, applies only to this software file. Patent licenses, if 17 * any, provided herein do not apply to combinations of this program with 18 * other software, or any other product whatsoever. 19 * 20 * You should have received a copy of the GNU General Public License along 21 * with this program; if not, write the Free Software Foundation, Inc., 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 * 24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 25 * Mountain View, CA 94043, or: 26 * 27 * http://www.sgi.com 28 * 29 * For further information regarding this notice, see: 30 * 31 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 32 * 33 */ 34 35 #include <sys/types.h> 36 #include <fcntl.h> 37 #include <errno.h> 38 #include <string.h> 39 #include <signal.h> 40 #include <unistd.h> 41 #include "test.h" 42 43 static void setup(void); 44 static void cleanup(void); 45 46 static char fname[255]; 47 static int fd; 48 static int whences[] = { 5, -1, 7 }; 49 50 char *TCID = "lseek03"; 51 int TST_TOTAL = ARRAY_SIZE(whences); 52 53 int main(int ac, char **av) 54 { 55 int lc; 56 57 tst_parse_opts(ac, av, NULL, NULL); 58 59 setup(); 60 61 for (lc = 0; TEST_LOOPING(lc); lc++) { 62 int i; 63 64 tst_count = 0; 65 66 for (i = 0; i < TST_TOTAL; i++) { 67 68 /* Call lseek(2) */ 69 TEST(lseek(fd, (off_t) 1, whences[i])); 70 71 if (TEST_RETURN == -1) { 72 if (TEST_ERRNO == EINVAL) { 73 tst_resm(TPASS, 74 "lseek(%s, 1, %d) Failed, errno=%d : %s", 75 fname, whences[i], 76 TEST_ERRNO, 77 strerror(TEST_ERRNO)); 78 } else { 79 tst_resm(TFAIL, 80 "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)", 81 fname, whences[i], 82 TEST_ERRNO, 83 strerror(TEST_ERRNO), 84 EINVAL); 85 } 86 } else { 87 tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld", 88 fname, whences[i], TEST_RETURN); 89 } 90 } 91 92 } 93 94 cleanup(); 95 tst_exit(); 96 } 97 98 void setup(void) 99 { 100 tst_sig(NOFORK, DEF_HANDLER, cleanup); 101 102 TEST_PAUSE; 103 104 tst_tmpdir(); 105 106 sprintf(fname, "tfile_%d", getpid()); 107 108 if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { 109 tst_brkm(TBROK, cleanup, 110 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", 111 fname, errno, strerror(errno)); 112 } 113 } 114 115 void cleanup(void) 116 { 117 if (close(fd) == -1) { 118 tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, 119 strerror(errno)); 120 } 121 122 tst_rmdir(); 123 } 124