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