Replace calls to ftell() with w->f_pos.