On Fri, Jan 16, 2004 at 05:19:29PM -0800, Ben Reser wrote:
> You're right. And this does work even on 32-bit big endian archs
> (except you need to cast what you want to shift or you'll get the wrong
> output.
>
> The following example code:
>
> long long min, max;
>
> min = (long long) (sizeof(long long) - 1) << (sizeof(long long)*8-1);
> max = ~min;
>
> printf("min=%lld\nmax=%lld\n",min,max);
> printf("min-1=%lld\nmax+1=%lld\n",min-1,max+1);
>
> Produces the following output:
>
> min=-9223372036854775808
> max=9223372036854775807
> min-1=9223372036854775807
> max+1=-9223372036854775808
>
> This is true on the follow archs:
> 32-bit little endian (i586)
> 32-bit bit enndia (ppc)
> 64-bit little endian (amd64)
> 64-bit big endian (sun4u)
>
> The min-1 and max+1 is there to prove that the 2s compliment is correct.
Based on the above the bounds svn_io_file_seek can be implemented like
so, which looks a whole lot nicer:
svn_error_t *
svn_io_file_seek (apr_file_t *file, apr_seek_where_t where,
svn_offset_t *offset, apr_pool_t *pool)
{
const apr_off_t min = ((apr_off_t) sizeof (apr_off_t)-1) <<
((sizeof (apr_off_t)*8)-1);
const apr_off_t max = ~min;
if (sizeof (apr_off_t) >= sizeof (svn_offset_t) ||
(*offset > min && *offset < max))
{
apr_off_t apr_offset = *offset;
return do_io_file_wrapper_cleanup
(file, apr_file_seek (file, where, &apr_offset),
"set psoition pointer in", pool);
}
else
{
return svn_error_create (SVN_ERR_IO_OFFSET_SIZE, NULL,
"Cannot seek file");
}
}
If nobody dislikes this I'll regen the patch on the issue with this
change.
--
Ben Reser <ben@reser.org>
http://ben.reser.org
"Conscience is the inner voice which warns us somebody may be looking."
- H.L. Mencken
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jan 17 02:37:14 2004