robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* ported from SPIE, section2/filesuite/stream3.c, by Airong Zhang */ |
| 21 | |
| 22 | /*====================================================================== |
| 23 | =================== TESTPLAN SEGMENT =================== |
| 24 | >KEYS: < fseek() ftell() |
| 25 | >WHAT: < 1) Ensure ftell reports the correct current byte offset. |
| 26 | >HOW: < 1) Open a file, write to it, reposition the file pointer and |
| 27 | check it. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | >BUGS: < |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 29 | ======================================================================*/ |
| 30 | #define _XOPEN_SOURCE 500 |
| 31 | #include <stdio.h> |
robbiew | a70576c | 2003-03-04 18:33:41 +0000 | [diff] [blame] | 32 | #include <errno.h> |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 33 | #include <fcntl.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/stat.h> |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 36 | #include <inttypes.h> |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 37 | #include "test.h" |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 38 | |
| 39 | char *TCID = "stream03"; |
| 40 | int TST_TOTAL = 1; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 41 | int local_flag; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 42 | |
| 43 | #define PASSED 1 |
| 44 | #define FAILED 0 |
| 45 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 46 | char progname[] = "stream03()"; |
| 47 | char tempfile1[40] = ""; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 48 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 49 | int main(int ac, char *av[]) |
| 50 | { |
| 51 | FILE *stream; |
| 52 | char buf[30]; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 53 | char *junk = "abcdefghijklmnopqrstuvwxyz"; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 54 | long pos; |
| 55 | off_t opos; |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 56 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 57 | const char *msg; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 58 | |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 59 | /* |
| 60 | * parse standard options |
| 61 | */ |
| 62 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 63 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 64 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 65 | |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 66 | local_flag = PASSED; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 67 | tst_tmpdir(); |
| 68 | |
| 69 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 70 | |
| 71 | sprintf(tempfile1, "stream03.%d", getpid()); |
| 72 | /*--------------------------------------------------------------------*/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 73 | //block0: |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 74 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | if ((stream = fopen(tempfile1, "a+")) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 76 | tst_brkm(TBROK, NULL, "fopen(%s) a+ failed: %s", |
| 77 | tempfile1, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 78 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 79 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 80 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 81 | /* make sure offset of zero at start */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 82 | pos = ftell(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 83 | |
| 84 | if (pos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | tst_resm(TFAIL, "file pointer descrepancy 1"); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 86 | local_flag = FAILED; |
| 87 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 88 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 89 | /* write something and check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 90 | if (fwrite(junk, sizeof(*junk), strlen(junk), stream) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 91 | tst_brkm(TFAIL, NULL, "fwrite failed: %s", |
| 92 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 93 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 94 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | pos = ftell(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 96 | |
| 97 | if (pos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 98 | tst_resm(TFAIL, |
| 99 | "strlen(junk)=%zi: file pointer descrepancy 2 (pos=%li)", |
| 100 | strlen(junk), pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 101 | local_flag = FAILED; |
| 102 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 103 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 104 | /* rewind and check */ |
| 105 | rewind(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 106 | pos = ftell(stream); |
| 107 | |
| 108 | if (pos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | tst_resm(TFAIL, |
| 110 | "file pointer descrepancy 3 (pos=%li, wanted pos=0)", |
| 111 | pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 112 | local_flag = FAILED; |
| 113 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 114 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 115 | /* seek from current position and then check */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 116 | if (fseek(stream, strlen(junk), 1) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 117 | tst_brkm(TFAIL, NULL, "fseek failed: %s", |
| 118 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 119 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 120 | |
| 121 | pos = ftell(stream); |
| 122 | |
| 123 | if (pos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | tst_resm(TFAIL, |
| 125 | "strlen(junk)=%zi: file pointer descrepancy 4 (pos=%li)", |
| 126 | strlen(junk), pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 127 | local_flag = FAILED; |
| 128 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 129 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 130 | /* seek from end of file and then check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 131 | if (fseek(stream, 0, 2) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 132 | tst_brkm(TFAIL, NULL, "fseek failed: %s", |
| 133 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 134 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 135 | |
| 136 | pos = ftell(stream); |
| 137 | |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 138 | if (pos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | tst_resm(TFAIL, |
| 140 | "strlen(junk)=%zi: file pointer descrepancy 5 (pos=%li)", |
| 141 | strlen(junk), pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 142 | local_flag = FAILED; |
| 143 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 144 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 145 | /* rewind with seek and then check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 146 | if (fseek(stream, 0, 0) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 147 | tst_brkm(TFAIL, NULL, "fseek failed: %s", |
| 148 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 149 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 150 | |
| 151 | pos = ftell(stream); |
| 152 | |
| 153 | if (pos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | tst_resm(TFAIL, |
| 155 | "file pointer descrepancy 6 (pos=%li, wanted pos=0)", |
| 156 | pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 157 | local_flag = FAILED; |
| 158 | } |
| 159 | |
| 160 | /* read till EOF, do getc and then check ftell */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 161 | while (fgets(buf, sizeof(buf), stream)) ; |
| 162 | pos = ftell(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 163 | getc(stream); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 164 | pos = ftell(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 165 | |
| 166 | if (pos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 167 | tst_resm(TFAIL, |
| 168 | "strlen(junk)=%zi: file pointer descrepancy 7 (pos=%li)", |
| 169 | strlen(junk), pos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 170 | local_flag = FAILED; |
| 171 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 172 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 173 | fclose(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 174 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 175 | if (local_flag == PASSED) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 176 | tst_resm(TPASS, "Test passed in block0."); |
| 177 | } else { |
| 178 | tst_resm(TFAIL, "Test failed in block0."); |
| 179 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 180 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 181 | local_flag = PASSED; |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 182 | |
| 183 | unlink(tempfile1); |
| 184 | /*--------------------------------------------------------------------*/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 185 | //block1: |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 186 | if ((stream = fopen(tempfile1, "a+")) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 187 | tst_brkm(TFAIL, NULL, "fopen(%s) a+ failed: %s", |
| 188 | tempfile1, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 189 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 190 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 191 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 192 | /* make sure offset of zero at start */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 193 | opos = ftello(stream); |
| 194 | |
| 195 | if (opos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | tst_resm(TFAIL, |
| 197 | "file pointer descrepancy 1 (opos=%" PRId64 |
| 198 | ", wanted opos=0)", (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 199 | local_flag = FAILED; |
| 200 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 201 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 202 | /* write something and check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 203 | if (fwrite(junk, sizeof(*junk), strlen(junk), stream) == 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 204 | tst_brkm(TFAIL, NULL, "fwrite failed: %s", |
| 205 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 206 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 207 | |
| 208 | opos = ftello(stream); |
| 209 | |
| 210 | if (opos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 211 | tst_resm(TFAIL, |
| 212 | "strlen(junk)=%zi: file pointer descrepancy 2 (opos=%" |
| 213 | PRId64 ")", strlen(junk), (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 214 | local_flag = FAILED; |
| 215 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 216 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 217 | /* rewind and check */ |
| 218 | rewind(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 219 | opos = ftello(stream); |
| 220 | |
| 221 | if (opos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 222 | tst_resm(TFAIL, |
| 223 | "file pointer descrepancy 3 (opos=%" PRId64 |
| 224 | ", wanted opos=0)", (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 225 | local_flag = FAILED; |
| 226 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 227 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 228 | /* seek from current position and then check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 229 | if (fseeko(stream, strlen(junk), 1) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 230 | tst_brkm(TFAIL, NULL, "fseeko failed: %s", |
| 231 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 232 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 233 | |
| 234 | opos = ftello(stream); |
| 235 | |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 236 | if (opos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 237 | tst_resm(TFAIL, |
| 238 | "strlen(junk)=%zi: file pointer descrepancy 4 (opos=%" |
| 239 | PRId64 ")", strlen(junk), (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 240 | local_flag = FAILED; |
| 241 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 242 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 243 | /* seek from end of file and then check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 244 | if (fseeko(stream, 0, 2) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 245 | tst_brkm(TFAIL, NULL, "fseeko failed: %s", |
| 246 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 247 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 248 | |
| 249 | opos = ftello(stream); |
| 250 | |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 251 | if (opos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 252 | tst_resm(TFAIL, |
| 253 | "strlen(junk)=%zi: file pointer descrepancy 5 (opos=%" |
| 254 | PRId64 ")", strlen(junk), (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 255 | local_flag = FAILED; |
| 256 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 257 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 258 | /* rewind with seek and then check */ |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 259 | if (fseeko(stream, 0, 0) != 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 260 | tst_brkm(TFAIL, NULL, "fseeko failed: %s", |
| 261 | strerror(errno)); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 262 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 263 | |
| 264 | opos = ftello(stream); |
| 265 | |
| 266 | if (opos != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 267 | tst_resm(TFAIL, |
| 268 | "file pointer descrepancy 6 (opos=%" PRId64 |
| 269 | ", wanted opos=0)", (int64_t) opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 270 | local_flag = FAILED; |
| 271 | } |
| 272 | |
| 273 | /* read till EOF, do getc and then check ftello */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 274 | while (fgets(buf, sizeof(buf), stream)) ; |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 275 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 276 | opos = ftello(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 277 | getc(stream); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 278 | opos = ftello(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 279 | |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 280 | if (opos != strlen(junk)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 281 | tst_resm(TFAIL, |
| 282 | "strlen(junk)=%zi: file pointer descrepancy 7 (opos=%li)", |
| 283 | strlen(junk), opos); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 284 | local_flag = FAILED; |
| 285 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 286 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 287 | fclose(stream); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 288 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 289 | if (local_flag == PASSED) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 290 | tst_resm(TPASS, "Test passed in block1."); |
| 291 | } else { |
| 292 | tst_resm(TFAIL, "Test failed in block1."); |
| 293 | } |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 294 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 295 | unlink(tempfile1); |
subrata_modak | da124b9 | 2009-10-13 14:00:45 +0000 | [diff] [blame] | 296 | } |
| 297 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 298 | tst_rmdir(); |
| 299 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 300 | } |