9000N/A /* Write a compiled module to a file, placing the time of last
9000N/A modification of its source into the header.
9000N/A- Errors are ignored, if a write error occurs an attempt is made to
9000N/A+ Write to a temporary file first so that creating the file is atomic.
9000N/A+ is made to remove the temporary file. */
9000N/A write_compiled_module(PyCodeObject *co, char *cpathname, long mtime)
9000N/A- fp = open_exclusive(cpathname);
9000N/A+ /* the temporary file is called cpathname + ".tmp" */
9000N/A+ if ((tmppathname = PyMem_Malloc(strlen(cpathname) + strlen(".tmp") + 1))
9000N/A+ fp = open_exclusive(tmppathname);
9000N/A- "# can't create %s\n", cpathname);
9000N/A+ "# can't create %s\n", tmppathname);
9000N/A PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);
9000N/A PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);
9000N/A if (fflush(fp) != 0 || ferror(fp)) {
9000N/A- PySys_WriteStderr("# can't write %s\n", cpathname);
9000N/A+ PySys_WriteStderr("# can't write %s\n", tmppathname);
9000N/A /* Don't keep partial file */
9000N/A+ (void) unlink(tmppathname);
9000N/A /* Now write the true mtime */
9000N/A PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
9000N/A+ /* Delete the old compiled file, if exists */
9000N/A+ /* the file exists but could not be deleted */
9000N/A+ "# can't unlink %s\n", cpathname);
9000N/A+ (void) unlink(tmppathname);
9000N/A+ /* rename the tmp file to the real file name */
9000N/A+ if (rename (tmppathname, cpathname)) {
9000N/A+ "# can't rename %s to %s\n", tmppathname, cpathname);
9000N/A+ (void) unlink(tmppathname);
9000N/A PySys_WriteStderr("# wrote %s\n", cpathname);