I could comment on type conversions, but... why ponder about unexpected type conversions in your code when you can avoid them completely? If portability is important, then don't use the default primitive data types. Use stdint.h instead.
- Swap
int
forint32_t
. - Swap
long
forint32_t
. - Keep size_t as it is, or swap it for
uint32_t
in case it matters. Most likely it does not.
And suddenly the code turned 100% portable.
Other comments:
- Why would you do
(void *)malloc(buf_size)
? Casting fromvoid*
tovoid*
doesn't make any sense. - For a hosted system, main() must always return
int
. Implicit int has been removed from the C language 15 years ago.