[PATCH v3 1/5] util: refactor fwrite