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