On Thu, Nov 12, 2009 at 11:41 AM, Ted Unangst <[email protected]> wrote:
>
> The harder way: Why are you casting an off_t to a size_t?
>

I want to verify a file's size before mmap'ing it.

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 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?

Thanks for the suggestions on a mailing list.

m

Reply via email to