int mwWriteFile(const char* filename, const char* str) { FILE* f; int rc; if (!str || !filename) { return 1; } f = mw_fopen(filename, "wb"); if (!f) { mwPerror("Writing file '%s'", filename); return 1; } rc = fputs(str, f); if (rc == EOF) { mwPerror("Error writing file '%s'", filename); } fcloseVerbose(f, filename, "Closing write file"); return rc; }
int writeCheckpoint(EvaluationState* es) { FILE* f; /* Avoid corrupting the checkpoint file by writing to a temporary file, and moving that */ f = mw_fopen(CHECKPOINT_FILE_TMP, "wb"); if (!f) { mwPerror("Opening checkpoint '%s'", CHECKPOINT_FILE_TMP); return 1; } es->lastCheckpointNuStep = es->nu_step; writeState(f, es); fclose(f); if (mw_rename(CHECKPOINT_FILE_TMP, resolvedCheckpointPath)) { mwPerror("Failed to update checkpoint file ('%s' to '%s')", CHECKPOINT_FILE_TMP, resolvedCheckpointPath ); return 1; } return 0; }
char* mwReadFile(const char* filename) { return mwFreadFileWithSize(mw_fopen(filename, "rb"), filename, NULL); }
char* mwReadFileWithSize(const char* filename, size_t* sizeOut) { return mwFreadFileWithSize(mw_fopen(filename, "rb"), filename, sizeOut); }