1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org> 3f08c3bdfSopenharmony_ci * 2004 Open Source Development Lab 4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 5f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 6f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 7f08c3bdfSopenharmony_ci * (at your option) any later version. 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 10f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 15f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 16f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17f08c3bdfSopenharmony_ci * 18f08c3bdfSopenharmony_ci * Module: .c 19f08c3bdfSopenharmony_ci */ 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci/* 22f08c3bdfSopenharmony_ci * Change History: 23f08c3bdfSopenharmony_ci * 24f08c3bdfSopenharmony_ci * 2/2004 Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP 25f08c3bdfSopenharmony_ci * 26f08c3bdfSopenharmony_ci */ 27f08c3bdfSopenharmony_ci#define _GNU_SOURCE 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci#include <stdlib.h> 30f08c3bdfSopenharmony_ci#include <sys/types.h> 31f08c3bdfSopenharmony_ci#include <signal.h> 32f08c3bdfSopenharmony_ci#include <fcntl.h> 33f08c3bdfSopenharmony_ci#include <stdio.h> 34f08c3bdfSopenharmony_ci#include <unistd.h> 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci#include "common_checkzero.h" 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ciint read_eof(char *filename) 39f08c3bdfSopenharmony_ci{ 40f08c3bdfSopenharmony_ci int fd; 41f08c3bdfSopenharmony_ci int i; 42f08c3bdfSopenharmony_ci int r; 43f08c3bdfSopenharmony_ci char buf[4096]; 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci if ((fd = open(filename, O_RDWR)) < 0) { 46f08c3bdfSopenharmony_ci fprintf(stderr, "can't open file %s \n", filename); 47f08c3bdfSopenharmony_ci exit(1); 48f08c3bdfSopenharmony_ci } 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_ci for (i = 0; i < 100000; i++) { 51f08c3bdfSopenharmony_ci off_t offset; 52f08c3bdfSopenharmony_ci char *bufoff; 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci offset = lseek(fd, 4096, SEEK_END); 55f08c3bdfSopenharmony_ci r = write(fd, "A", 1); 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_ci offset = lseek(fd, offset - 4096, SEEK_SET); 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci r = read(fd, buf, 4096); 60f08c3bdfSopenharmony_ci if (r > 0) { 61f08c3bdfSopenharmony_ci if ((bufoff = check_zero(buf, r))) { 62f08c3bdfSopenharmony_ci fprintf(stderr, "non-zero read at offset %p\n", 63f08c3bdfSopenharmony_ci offset + bufoff); 64f08c3bdfSopenharmony_ci exit(1); 65f08c3bdfSopenharmony_ci } 66f08c3bdfSopenharmony_ci } 67f08c3bdfSopenharmony_ci } 68f08c3bdfSopenharmony_ci fprintf(stderr, "read_checkzero done\n"); 69f08c3bdfSopenharmony_ci return 0; 70f08c3bdfSopenharmony_ci} 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_ciint main(int argc, char **argv) 73f08c3bdfSopenharmony_ci{ 74f08c3bdfSopenharmony_ci if (argc < 2) { 75f08c3bdfSopenharmony_ci printf("You must pass a filename to the test \n"); 76f08c3bdfSopenharmony_ci exit(1); 77f08c3bdfSopenharmony_ci } 78f08c3bdfSopenharmony_ci 79f08c3bdfSopenharmony_ci char *filename = argv[1]; 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ci read_eof(filename); 82f08c3bdfSopenharmony_ci 83f08c3bdfSopenharmony_ci return 0; 84f08c3bdfSopenharmony_ci} 85