1 /*
2 * Copyright (c) 2004 Daniel McNeil <daniel@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@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
check_zero(unsigned char * buf,int size)36 char *check_zero(unsigned char *buf, int size)
37 {
38 unsigned char *p;
39
40 p = buf;
41
42 while (size > 0) {
43 if (*buf != 0) {
44 fprintf(stderr,
45 "non zero buffer at buf[%d] => 0x%02x,%02x,%02x,%02x\n",
46 buf - p, (unsigned int)buf[0],
47 size > 1 ? (unsigned int)buf[1] : 0,
48 size > 2 ? (unsigned int)buf[2] : 0,
49 size > 3 ? (unsigned int)buf[3] : 0);
50 fprintf(stderr, "buf %p, p %p\n", buf, p);
51 return buf;
52 }
53 buf++;
54 size--;
55 }
56 return 0; /* all zeros */
57 }
58
read_eof(char * filename)59 int read_eof(char *filename)
60 {
61 int fd;
62 int i;
63 int r;
64 char buf[4096];
65
66 if ((fd = open(filename, O_RDWR)) < 0) {
67 fprintf(stderr, "can't open file %s \n", filename);
68 exit(1);
69 }
70
71 for (i = 0; i < 100000; i++) {
72 off_t offset;
73 char *bufoff;
74
75 offset = lseek(fd, 4096, SEEK_END);
76 r = write(fd, "A", 1);
77
78 offset = lseek(fd, offset - 4096, SEEK_SET);
79
80 r = read(fd, buf, 4096);
81 if (r > 0) {
82 if ((bufoff = check_zero(buf, r))) {
83 fprintf(stderr, "non-zero read at offset %p\n",
84 offset + bufoff);
85 exit(1);
86 }
87 }
88 }
89 fprintf(stderr, "read_checkzero done\n");
90 return 0;
91 }
92
main(int argc,char ** argv)93 int main(int argc, char **argv)
94 {
95 if (argc < 2) {
96 printf("You must pass a filename to the test \n");
97 exit(1);
98 }
99
100 char *filename = argv[1];
101
102 read_eof(filename);
103
104 return 0;
105 }
106