On Thu, Nov 12, 2009 at 12:06 PM, Mark Bucciarelli <[email protected]> wrote:
> The file holds a number of structs each of size size_t.  I stat
> the file, compute records_n, then make sure the product of
> records_n and struct size is exactly equal to the file size.

The size of size_t is variable, so you need to decide whether you
actually meant 4 bytes or 8 bytes.  Also, the length argument to mmap
is size_t, not off_t, so even if you did the multiply check properly,
you'd be truncating on the mmap call.

>
> The ptrdiff_t question is similar:
>
> p0 = (mystruct *) mmap(...);
> if (p0 == -1) err(1, "boom!");
> for (p = p0; p < p0 + records_n; p++)
>   do_something_with(p);
>
> Is there a portable way to code these two tasks?

What's wrong with p0 + records_n?

Reply via email to