Diff
Not logged in

Differences From Artifact [85448dd1b7]:

To Artifact [74fe94410e]:


658
659
660
661
662
663
664
665

666
667
668
669
670
671
672
658
659
660
661
662
663
664

665
666
667
668
669
670
671
672







-
+







 */

TclFile
TclpCreateTempFile(
    const char *contents)	/* String to write into temp file, or NULL. */
{
    WCHAR name[MAX_PATH];
    const char *native;
    const char *native = NULL;
    Tcl_DString dstring;
    HANDLE handle;

    if (TempFileName(name) == 0) {
	return NULL;
    }

686
687
688
689
690
691
692
693




694
695
696
697
698
699
700
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700
701
702
703







-
+
+
+
+







	const char *p;
	int toCopy;

	/*
	 * Convert the contents from UTF to native encoding
	 */

	native = Tcl_UtfToExternalDString(NULL, contents, TCL_INDEX_NONE, &dstring);
	if (Tcl_UtfToExternalDStringEx(NULL, NULL, contents, TCL_INDEX_NONE, 0, &dstring, NULL) != TCL_OK) {
	   goto error;
	}
	native = Tcl_DStringValue(&dstring);

	toCopy = Tcl_DStringLength(&dstring);
	for (p = native; toCopy > 0; p++, toCopy--) {
	    if (*p == '\n') {
		length = p - native;
		if (length > 0) {
		    if (!WriteFile(handle, native, length, &result, NULL)) {
726
727
728
729
730
731
732

733


734
735
736
737
738
739
740
729
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744
745







+
-
+
+







     * Free the native representation of the contents if necessary.
     */

    if (contents != NULL) {
	Tcl_DStringFree(&dstring);
    }

    if (native != NULL) {
    Tcl_WinConvertError(GetLastError());
	Tcl_WinConvertError(GetLastError());
    }
    CloseHandle(handle);
    DeleteFileW(name);
    return NULL;
}

/*
 *----------------------------------------------------------------------