1 /* 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. 3 * Copyright (c) 2017 Fujitsu Ltd. 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 #include <errno.h> 35 #include "tst_test.h" 36 37 #define SIZE 512 38 39 static int fd; 40 static char buf[SIZE]; 41 42 static void verify_read(void) 43 { 44 SAFE_LSEEK(fd, 0, SEEK_SET); 45 46 TEST(read(fd, buf, SIZE)); 47 48 if (TEST_RETURN == -1) 49 tst_res(TFAIL | TTERRNO, "read(2) failed"); 50 else 51 tst_res(TPASS, "read(2) returned %ld", TEST_RETURN); 52 } 53 54 static void setup(void) 55 { 56 memset(buf, '*', SIZE); 57 fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0700); 58 SAFE_WRITE(1, fd, buf, SIZE); 59 } 60 61 static void cleanup(void) 62 { 63 if (fd > 0) 64 SAFE_CLOSE(fd); 65 } 66 67 static struct tst_test test = { 68 .test_all = verify_read, 69 .setup = setup, 70 .cleanup = cleanup, 71 .needs_tmpdir = 1, 72 }; 73