[PATCH v2 1/5] util: refactor fwrite