summaryrefslogtreecommitdiffstats
path: root/private/crt32/lowio/initcon.c
blob: 0302e5d84ae97eed05360bcb665a4a0f1b905109 (plain) (blame)
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
/***
*_initcon.c - direct console I/O initialization and termination for Win32
*
*	Copyright (c) 1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Defines _initcon() and _termcon() routines.
*
*	NOTE: The _initcon() and _termcon() routines are called indirectly
*	by the startup and termination code, thru the pointers _pinitcon
*	and _ptermcon.
*
*Revision History:
*	07-26-91  GJF	Module created. Based on the original code by Stevewo
*			(which was distributed across several sources).
*	03-12-92  SKS	Split out initializer
*
*******************************************************************************/

#include <cruntime.h>
#include <oscalls.h>

void __cdecl _initcon(void);
void __cdecl _termcon(void);

#ifdef	_MSC_VER

#pragma data_seg(".CRT$XIC")
static  void (__cdecl *pinit)(void) = _initcon;

#pragma data_seg(".CRT$XPX")
static  void (__cdecl *pterm)(void) = _termcon;

#pragma data_seg()

#endif	/* _MSC_VER */

/*
 * define console handles. these definitions cause this file to be linked
 * in if one of the direct console I/O functions is referenced.
 */
int _coninpfh = -1;	/* console input */
int _confh = -1;	/* console output */

/***
*void _initcon(void) - open handles for console I/O
*
*Purpose:
*	Opens handles for console input and output.
*
*Entry:
*	None.
*
*Exit:
*	No return value. If successful, handle values are copied into the
*	global variables _coninpfh and _confh.
*
*Exceptions:
*
*******************************************************************************/

void __cdecl _initcon (
	void
	)
{
	_coninpfh = (int)CreateFile( "CONIN$",
				     GENERIC_READ | GENERIC_WRITE,
				     FILE_SHARE_READ | FILE_SHARE_WRITE,
				     NULL,
				     OPEN_EXISTING,
				     0,
				     NULL
				    );

	_confh = (int)CreateFile( "CONOUT$",
				  GENERIC_WRITE,
				  FILE_SHARE_READ | FILE_SHARE_WRITE,
				  NULL,
				  OPEN_EXISTING,
				  0,
				  NULL
				);
}


/***
*void _termcon(void) - close console I/O handles
*
*Purpose:
*	Closes _coninpfh and _confh.
*
*Entry:
*	None.
*
*Exit:
*	No return value.
*
*Exceptions:
*
*******************************************************************************/

void __cdecl _termcon (
	void
	)
{
	if ( _confh != -1 ) {
		CloseHandle( (HANDLE)_confh );
	}

	if ( _coninpfh != -1 ) {
		CloseHandle( (HANDLE)_coninpfh );
	}
}