summaryrefslogtreecommitdiffstats
path: root/PC/bdist_wininst
Commit message (Expand)AuthorAgeFilesLines
* Issue #18571: Implementation of the PEP 446: file descriptors and file handlesVictor Stinner2013-08-271-1/+1
* Fixes issue4653 - Correctly specify the buffer size to FormatMessageW andGregory P. Smith2013-03-232-2/+2
* #11565: Fix several typos. Patch by Piotr Kasprzyk.Ezio Melotti2011-03-162-4/+4
* #11515: fix several typos. Patch by Piotr Kasprzyk.Ezio Melotti2011-03-151-1/+1
* Convert DOS files to CRLF. This doesn't touch the .hgeol settings, so that th...Martin v. Löwis2011-03-066-726/+726
* Recorded merge of revisions 81032 via svnmerge fromAntoine Pitrou2010-05-093-2421/+2421
* Fix issue5076: bdist_wininst fails on py3kMark Hammond2009-01-291-7/+40
* Merged revisions 69094 via svnmerge fromMark Hammond2009-01-291-89/+90
* Merged revisions 63828 via svnmerge fromGeorg Brandl2008-07-161-7/+19
* Merged revisions 62425-62429,62434-62436,62441,62444,62446-62448,62450-62455,...Christian Heimes2008-05-043-8/+112
* #1535: rename __builtin__ module to builtins.Georg Brandl2007-12-021-1/+1
* Four months of trunk changes (including a few releases...)Thomas Wouters2006-12-132-0/+339
* Remove .cvsignore files, as they live in svn:ignoreMartin v. Löwis2005-10-301-8/+0
* Running a bdist_wininst installer, built with Python 2.3, installingThomas Heller2005-02-031-8/+25
* Set PYTHONHOME before loading Python, so that sys.path will be set correctly.Thomas Heller2005-02-031-1/+7
* Close stdout and stderr, which are redirected into a temp file, beforeThomas Heller2004-12-221-1/+7
* printf format code for integers is %d not %s.Thomas Heller2004-12-011-1/+1
* Running the pre-install or post-install script did not work whenThomas Heller2004-12-011-3/+6
* The binary layout of cfgdata has changed, so the magic number has toThomas Heller2004-07-191-1/+5
* Ignore some more build products.Thomas Heller2004-07-141-0/+4
* Add a warning so that it isn't forgotten to recreate the binaries ANDThomas Heller2004-07-145-0/+45
* Don't complain that non-existant registry entries cannot be deleted.Thomas Heller2004-07-141-2/+2
* Remove the annoing and useless messagebox asking about overwriting files.Thomas Heller2004-07-071-25/+0
* Patch [ 983775 ] Allow bdist_wininst to install for non-admin usersMark Hammond2004-07-021-41/+118
* Fix for SF 982215: bdist_wininst - Next button not greyed out during file copy.Thomas Heller2004-07-021-0/+8
* The wininst.exe is no longer compressed with UPX.Thomas Heller2004-06-182-9/+3
* When loading the Python dll to run the postinstall script, try to loadThomas Heller2004-06-181-4/+20
* The wininst-6.exe template binary for bdist_wininst is now linkedThomas Heller2004-04-161-2/+2
* The wininst-7.1.exe template binary for bdist_wininst is now linkedThomas Heller2004-04-161-5/+5
* Minor reformatting.Thomas Heller2004-04-151-4/+5
* Solution and project file to build wininstXX.exe with MSVC7.1 (VisualThomas Heller2004-02-202-0/+236
* To avoid problems with conflicting dlls, the windows installers builtThomas Heller2004-02-201-3/+3
* Patch #892660 from Mark Hammond, for distutils bdist_wininst command.Thomas Heller2004-02-201-50/+177
* Oops, MSVC was still open, so the project file was not yet saved.Thomas Heller2002-11-221-6/+7
* Copied the sources from the distutils CVS repository.Thomas Heller2002-11-2210-0/+3125
_stop_regexp_test_crash'>dgp_stop_regexp_test_crash Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/win/stub16.c
blob: 7114d4e66ddabbb16a606ce9ae24858ea7fc6deb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* 
 * stub16.c 
 *
 *	A helper program used for running 16-bit DOS applications under
 *	Windows 95.
 *
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: stub16.c,v 1.4 1999/04/21 21:50:34 rjohnson Exp $
 */

#define STRICT

#include <windows.h>
#include <stdio.h>

static HANDLE		CreateTempFile(void);

/*
 *---------------------------------------------------------------------------
 *
 * main
 *
 *	Entry point for the 32-bit console mode app used by Windows 95 to
 *	help run the 16-bit program specified on the command line.
 *
 *	1. EOF on a pipe that connects a detached 16-bit process and a
 *	32-bit process is never seen.  So, this process runs the 16-bit
 *	process _attached_, and then it is run detached from the calling
 *	32-bit process.  
 * 
 *	2. If a 16-bit process blocks reading from or writing to a pipe,
 *	it never wakes up, and eventually brings the whole system down
 *	with it if you try to kill the process.  This app simulates
 *	pipes.  If any of the stdio handles is a pipe, this program
 *	accumulates information into temp files and forwards it to or
 *	from the DOS application as appropriate.  This means that this
 *	program must receive EOF from a stdin pipe before it will actually
 *	start the DOS app, and the DOS app must finish generating stdout
 *	or stderr before the data will be sent to the next stage of the
 *	pipe.  If the stdio handles are not pipes, no accumulation occurs
 *	and the data is passed straight through to and from the DOS
 *	application.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The child process is created and this process waits for it to
 *	complete.
 *
 *---------------------------------------------------------------------------
 */

int
main()
{
    DWORD dwRead, dwWrite;
    char *cmdLine;
    HANDLE hStdInput, hStdOutput, hStdError;
    HANDLE hFileInput, hFileOutput, hFileError;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    char buf[8192];
    DWORD result;

    hFileInput = INVALID_HANDLE_VALUE;
    hFileOutput = INVALID_HANDLE_VALUE;
    hFileError = INVALID_HANDLE_VALUE;
    result = 1;

    /*
     * Don't get command line from argc, argv, because the command line
     * tokenizer will have stripped off all the escape sequences needed
     * for quotes and backslashes, and then we'd have to put them all
     * back in again.  Get the raw command line and parse off what we
     * want ourselves.  The command line should be of the form:
     *
     * stub16.exe program arg1 arg2 ...
     */

    cmdLine = strchr(GetCommandLine(), ' ');
    if (cmdLine == NULL) {
	return 1;
    }
    cmdLine++;

    hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    hStdError = GetStdHandle(STD_ERROR_HANDLE);

    if (GetFileType(hStdInput) == FILE_TYPE_PIPE) {
	hFileInput = CreateTempFile();
	if (hFileInput == INVALID_HANDLE_VALUE) {
	    goto cleanup;
	}
	while (ReadFile(hStdInput, buf, sizeof(buf), &dwRead, NULL) != FALSE) {
	    if (dwRead == 0) {
		break;
	    }
	    if (WriteFile(hFileInput, buf, dwRead, &dwWrite, NULL) == FALSE) {
		goto cleanup;
	    }
	}
	SetFilePointer(hFileInput, 0, 0, FILE_BEGIN);
	SetStdHandle(STD_INPUT_HANDLE, hFileInput);
    }
    if (GetFileType(hStdOutput) == FILE_TYPE_PIPE) {
	hFileOutput = CreateTempFile();
	if (hFileOutput == INVALID_HANDLE_VALUE) {
	    goto cleanup;
	}
	SetStdHandle(STD_OUTPUT_HANDLE, hFileOutput);
    }
    if (GetFileType(hStdError) == FILE_TYPE_PIPE) {
	hFileError = CreateTempFile();
	if (hFileError == INVALID_HANDLE_VALUE) {
	    goto cleanup;
	}
	SetStdHandle(STD_ERROR_HANDLE, hFileError);
    }

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    if (CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, 
	    &pi) == FALSE) {
	goto cleanup;
    }

    WaitForInputIdle(pi.hProcess, 5000);
    WaitForSingleObject(pi.hProcess, INFINITE);
    GetExitCodeProcess(pi.hProcess, &result);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

    if (hFileOutput != INVALID_HANDLE_VALUE) {
	SetFilePointer(hFileOutput, 0, 0, FILE_BEGIN);
	while (ReadFile(hFileOutput, buf, sizeof(buf), &dwRead, NULL) != FALSE) {
	    if (dwRead == 0) {
		break;
	    }
	    if (WriteFile(hStdOutput, buf, dwRead, &dwWrite, NULL) == FALSE) {
		break;
	    }
	}
    }
    if (hFileError != INVALID_HANDLE_VALUE) {
	SetFilePointer(hFileError, 0, 0, FILE_BEGIN);
	while (ReadFile(hFileError, buf, sizeof(buf), &dwRead, NULL) != FALSE) {
	    if (dwRead == 0) {
		break;
	    }
	    if (WriteFile(hStdError, buf, dwRead, &dwWrite, NULL) == FALSE) {
		break;
	    }
	}
    }

cleanup:
    if (hFileInput != INVALID_HANDLE_VALUE) {
	CloseHandle(hFileInput);
    }
    if (hFileOutput != INVALID_HANDLE_VALUE) {
	CloseHandle(hFileOutput);
    }
    if (hFileError != INVALID_HANDLE_VALUE) {
	CloseHandle(hFileError);
    }
    CloseHandle(hStdInput);
    CloseHandle(hStdOutput);
    CloseHandle(hStdError);
    ExitProcess(result);
    return 1;
}

static HANDLE
CreateTempFile()
{
    char name[MAX_PATH];
    SECURITY_ATTRIBUTES sa;

    if (GetTempPath(sizeof(name), name) == 0) {
	return INVALID_HANDLE_VALUE;
    }
    if (GetTempFileName(name, "tcl", 0, name) == 0) {
	return INVALID_HANDLE_VALUE;
    }

    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;
    return CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, &sa, 
	    CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,
	    NULL);
}