This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Reset cached offset when reading to end of stream (BZ #17653)
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org, carlos at redhat dot com
- Date: Thu, 27 Nov 2014 14:26:03 +0100
- Subject: Re: [PATCH] Reset cached offset when reading to end of stream (BZ #17653)
- Authentication-results: sourceware.org; auth=none
- References: <20141127122839 dot GA31809 at spoyarek dot pnq dot redhat dot com>
Siddhesh Poyarekar <siddhesh@redhat.com> writes:
> @@ -348,12 +352,44 @@ do_ftell_test (const char *filename)
>
> if (off != test_modes[i].new_off)
> {
> - printf ("Incorrect new offset. Expected %zu but got %ld\n",
> + printf ("Incorrect new offset. Expected %zu but got %ld, ",
> test_modes[i].new_off, off);
> ret |= 1;
> }
> else
> - printf ("new offset = %ld\n", off);
> + printf ("new offset = %ld, ", off);
> +
> + /* Read to the end, write some data to the fd and check if ftell can
> + see the new ofset. Do this test only for files that allow
> + reading. */
> + if (test_modes[i].fd_mode != O_WRONLY)
> + {
> + char tmpbuf[data_len];
> +
> + rewind (fp);
> +
> + while (fgets_func (tmpbuf, sizeof (tmpbuf), fp) && !feof (fp));
> +
> + write_ret = write (fd, data, data_len);
> + if (write_ret != data_len)
> + {
> + printf ("write failed (%m)\n");
> + ret |= 1;
> + }
> + off = ftell (fp);
> +
> + if (off != test_modes[i].eof_off)
> + {
> + printf ("Incorrect offset after read EOF. "
> + "Expected %zu but got %ld\n",
> + test_modes[i].eof_off, off);
> + ret |= 1;
> + }
> + else
> + printf ("offset after EOF = %ld\n", off);
> + }
> + else
> + putc ('\n', stdout);
This resulting output will have an ugly trailing comma if fd_mode ==
O_WRONLY.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."