blob: 7e4c417739b037000557b580263960d72c9fcd61 [file] [log] [blame]
Fred Drakec7b72db1999-02-16 19:18:38 +00001\section{\module{msvcrt} --
2 Useful routines from the MS VC++ runtime}
3
4\declaremodule{builtin}{msvcrt}
Fred Drakef6863c11999-03-02 16:37:17 +00005 \platform{Windows}
Fred Drakec7b72db1999-02-16 19:18:38 +00006\modulesynopsis{Miscellaneous useful routines from the MS VC++ runtime.}
7\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
8
9
10These functions provide access to some useful capabilities on Windows
11platforms. Some higher-level modules use these functions to build the
12Windows implementations of their services. For example, the
13\refmodule{getpass} module uses this in the implementation of the
14\function{getpass()} function.
15
16Further documentation on these functions can be found in the Platform
17API documentation.
18
19
20\subsection{File Operations \label{msvcrt-files}}
21
22\begin{funcdesc}{locking}{fd, mode, nbytes}
23 Lock part of a file based on a file descriptor from the C runtime.
24 Raises \exception{IOError} on failure.
25\end{funcdesc}
26
27\begin{funcdesc}{setmode}{fd, flags}
28 Set the line-end translation mode for the file descriptor \var{fd}.
Fred Drake85a59dd1999-02-16 19:41:01 +000029 To set it to text mode, \var{flags} should be \constant{os.O_TEXT};
30 for binary, it should be \constant{os.O_BINARY}.
Fred Drakec7b72db1999-02-16 19:18:38 +000031\end{funcdesc}
32
33\begin{funcdesc}{open_osfhandle}{handle, flags}
34 Create a C runtime file descriptor from the file handle
35 \var{handle}. The \var{flags} parameter should be a bit-wise OR of
Fred Drake85a59dd1999-02-16 19:41:01 +000036 \constant{os.O_APPEND}, \constant{os.O_RDONLY}, and
37 \constant{os.O_TEXT}. The returned file descriptor may be used as a
38 parameter to \function{os.fdopen()} to create a file object.
Fred Drakec7b72db1999-02-16 19:18:38 +000039\end{funcdesc}
40
41\begin{funcdesc}{get_osfhandle}{fd}
42 Return the file handle for the file descriptor \var{fd}. Raises
43 \exception{IOError} if \var{fd} is not recognized.
44\end{funcdesc}
45
46
47\subsection{Console I/O \label{msvcrt-console}}
48
49\begin{funcdesc}{kbhit}{}
50 Return true if a keypress is waiting to be read.
51\end{funcdesc}
52
53\begin{funcdesc}{getch}{}
54 Read a keypress and return the resulting character. Nothing is
55 echoed to the console. This call will block if a keypress is not
56 already available, but will not wait for \kbd{Enter} to be pressed.
57 If the pressed key was a special function key, this will return
58 \code{'\e000'} or \code{'\e xe0'}; the next call will return the
59 keycode. The \kbd{Control-C} keypress cannot be read with this
60 function.
61\end{funcdesc}
62
63\begin{funcdesc}{getche}{}
64 Similar to \function{getch()}, but the keypress will be echoed if it
65 represents a printable character.
66\end{funcdesc}
67
68\begin{funcdesc}{putch}{char}
69 Print the character \var{char} to the console without buffering.
70\end{funcdesc}
71
72\begin{funcdesc}{ungetch}{char}
73 Cause the character \var{char} to be ``pushed back'' into the
74 console buffer; it will be the next character read by
75 \function{getch()} or \function{getche()}.
76\end{funcdesc}
77
78
79\subsection{Other Functions \label{msvcrt-other}}
80
81\begin{funcdesc}{heapmin}{}
82 Force the \cfunction{malloc()} heap to clean itself up and return
83 unused blocks to the operating system. This only works on Windows
84 NT. On failure, this raises \exception{IOError}.
85\end{funcdesc}