This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Reset cached offset when reading to end of stream (BZ #17653)


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."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]