Suppose I want to read an entire file in memory. I'd open it in binary mode, use fseek to get to the end of the file, then do ftell to get its size.
Then I would allocate a string with the same size as the file, and just read it in, right?
The problem is that ftell returns a long int, and malloc should receive a size_t argument. Now, size_t can be larger than long int as far as I can tell (I've just checked C: a reference manual by Harbison and Steele, and Chapter 11 mentions that size_t can be defined as unsigned long long, depending on the compiler). I suppose the opposite could be true (and that would be a real problem, since I'd be casting a long long into a long, or something like that)
So my question is how do I deal with that?
Thanks!
edit: thanks guys, that was really quick! I'll use mmap (and posix_madvise too, which I've found after diggin up info about mmap)!