Use ftello() and fseeko() instead of ftell() and fseek() everywhere.