blob: c8e6ed8533f81fc0833dc32af84e81cc8a34ae6c [file] [log] [blame]
Zachary Ware45520892015-05-13 01:22:32 -05001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(msvcrt_heapmin__doc__,
6"heapmin($module, /)\n"
7"--\n"
8"\n"
9"Minimize the malloc() heap.\n"
10"\n"
11"Force the malloc() heap to clean itself up and return unused blocks\n"
12"to the operating system. On failure, this raises OSError.");
13
14#define MSVCRT_HEAPMIN_METHODDEF \
15 {"heapmin", (PyCFunction)msvcrt_heapmin, METH_NOARGS, msvcrt_heapmin__doc__},
16
17static PyObject *
18msvcrt_heapmin_impl(PyModuleDef *module);
19
20static PyObject *
21msvcrt_heapmin(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
22{
23 return msvcrt_heapmin_impl(module);
24}
25
26PyDoc_STRVAR(msvcrt_locking__doc__,
27"locking($module, fd, mode, nbytes, /)\n"
28"--\n"
29"\n"
30"Lock part of a file based on file descriptor fd from the C runtime.\n"
31"\n"
32"Raises IOError on failure. The locked region of the file extends from\n"
33"the current file position for nbytes bytes, and may continue beyond\n"
34"the end of the file. mode must be one of the LK_* constants listed\n"
35"below. Multiple regions in a file may be locked at the same time, but\n"
36"may not overlap. Adjacent regions are not merged; they must be unlocked\n"
37"individually.");
38
39#define MSVCRT_LOCKING_METHODDEF \
40 {"locking", (PyCFunction)msvcrt_locking, METH_VARARGS, msvcrt_locking__doc__},
41
42static PyObject *
43msvcrt_locking_impl(PyModuleDef *module, int fd, int mode, long nbytes);
44
45static PyObject *
46msvcrt_locking(PyModuleDef *module, PyObject *args)
47{
48 PyObject *return_value = NULL;
49 int fd;
50 int mode;
51 long nbytes;
52
Zachary Ware77772c02015-05-13 10:58:35 -050053 if (!PyArg_ParseTuple(args, "iil:locking",
Zachary Ware45520892015-05-13 01:22:32 -050054 &fd, &mode, &nbytes))
55 goto exit;
56 return_value = msvcrt_locking_impl(module, fd, mode, nbytes);
57
58exit:
59 return return_value;
60}
61
62PyDoc_STRVAR(msvcrt_setmode__doc__,
63"setmode($module, fd, mode, /)\n"
64"--\n"
65"\n"
66"Set the line-end translation mode for the file descriptor fd.\n"
67"\n"
68"To set it to text mode, flags should be os.O_TEXT; for binary, it\n"
69"should be os.O_BINARY.\n"
70"\n"
71"Return value is the previous mode.");
72
73#define MSVCRT_SETMODE_METHODDEF \
74 {"setmode", (PyCFunction)msvcrt_setmode, METH_VARARGS, msvcrt_setmode__doc__},
75
76static long
77msvcrt_setmode_impl(PyModuleDef *module, int fd, int flags);
78
79static PyObject *
80msvcrt_setmode(PyModuleDef *module, PyObject *args)
81{
82 PyObject *return_value = NULL;
83 int fd;
84 int flags;
85 long _return_value;
86
Zachary Ware77772c02015-05-13 10:58:35 -050087 if (!PyArg_ParseTuple(args, "ii:setmode",
Zachary Ware45520892015-05-13 01:22:32 -050088 &fd, &flags))
89 goto exit;
90 _return_value = msvcrt_setmode_impl(module, fd, flags);
91 if ((_return_value == -1) && PyErr_Occurred())
92 goto exit;
93 return_value = PyLong_FromLong(_return_value);
94
95exit:
96 return return_value;
97}
98
99PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
100"open_osfhandle($module, handle, flags, /)\n"
101"--\n"
102"\n"
103"Create a C runtime file descriptor from the file handle handle.\n"
104"\n"
105"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n"
106"and os.O_TEXT. The returned file descriptor may be used as a parameter\n"
107"to os.fdopen() to create a file object.");
108
109#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \
110 {"open_osfhandle", (PyCFunction)msvcrt_open_osfhandle, METH_VARARGS, msvcrt_open_osfhandle__doc__},
111
112static long
Zachary Ware77772c02015-05-13 10:58:35 -0500113msvcrt_open_osfhandle_impl(PyModuleDef *module, Py_intptr_t handle,
114 int flags);
Zachary Ware45520892015-05-13 01:22:32 -0500115
116static PyObject *
117msvcrt_open_osfhandle(PyModuleDef *module, PyObject *args)
118{
119 PyObject *return_value = NULL;
120 Py_intptr_t handle;
121 int flags;
122 long _return_value;
123
Zachary Ware77772c02015-05-13 10:58:35 -0500124 if (!PyArg_ParseTuple(args, ""_Py_PARSE_INTPTR"i:open_osfhandle",
Zachary Ware45520892015-05-13 01:22:32 -0500125 &handle, &flags))
126 goto exit;
127 _return_value = msvcrt_open_osfhandle_impl(module, handle, flags);
128 if ((_return_value == -1) && PyErr_Occurred())
129 goto exit;
130 return_value = PyLong_FromLong(_return_value);
131
132exit:
133 return return_value;
134}
135
136PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
137"get_osfhandle($module, fd, /)\n"
138"--\n"
139"\n"
140"Return the file handle for the file descriptor fd.\n"
141"\n"
142"Raises IOError if fd is not recognized.");
143
144#define MSVCRT_GET_OSFHANDLE_METHODDEF \
145 {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
146
147static Py_intptr_t
148msvcrt_get_osfhandle_impl(PyModuleDef *module, int fd);
149
150static PyObject *
151msvcrt_get_osfhandle(PyModuleDef *module, PyObject *arg)
152{
153 PyObject *return_value = NULL;
154 int fd;
155 Py_intptr_t _return_value;
156
Zachary Ware77772c02015-05-13 10:58:35 -0500157 if (!PyArg_Parse(arg, "i:get_osfhandle", &fd))
Zachary Ware45520892015-05-13 01:22:32 -0500158 goto exit;
159 _return_value = msvcrt_get_osfhandle_impl(module, fd);
160 if ((_return_value == -1) && PyErr_Occurred())
161 goto exit;
162 return_value = PyLong_FromVoidPtr((void *)_return_value);
163
164exit:
165 return return_value;
166}
167
168PyDoc_STRVAR(msvcrt_kbhit__doc__,
169"kbhit($module, /)\n"
170"--\n"
171"\n"
172"Return true if a keypress is waiting to be read.");
173
174#define MSVCRT_KBHIT_METHODDEF \
175 {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__},
176
177static long
178msvcrt_kbhit_impl(PyModuleDef *module);
179
180static PyObject *
181msvcrt_kbhit(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
182{
183 PyObject *return_value = NULL;
184 long _return_value;
185
186 _return_value = msvcrt_kbhit_impl(module);
187 if ((_return_value == -1) && PyErr_Occurred())
188 goto exit;
189 return_value = PyLong_FromLong(_return_value);
190
191exit:
192 return return_value;
193}
194
195PyDoc_STRVAR(msvcrt_getch__doc__,
196"getch($module, /)\n"
197"--\n"
198"\n"
199"Read a keypress and return the resulting character as a byte string.\n"
200"\n"
201"Nothing is echoed to the console. This call will block if a keypress is\n"
202"not already available, but will not wait for Enter to be pressed. If the\n"
203"pressed key was a special function key, this will return \'\\000\' or\n"
204"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n"
205"cannot be read with this function.");
206
207#define MSVCRT_GETCH_METHODDEF \
208 {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__},
209
210static int
211msvcrt_getch_impl(PyModuleDef *module);
212
213static PyObject *
214msvcrt_getch(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
215{
216 PyObject *return_value = NULL;
217 char s[1];
218
219 s[0] = msvcrt_getch_impl(module);
220 return_value = PyBytes_FromStringAndSize(s, 1);
221
222 return return_value;
223}
224
Zachary Ware45520892015-05-13 01:22:32 -0500225PyDoc_STRVAR(msvcrt_getwch__doc__,
226"getwch($module, /)\n"
227"--\n"
228"\n"
229"Wide char variant of getch(), returning a Unicode value.");
230
231#define MSVCRT_GETWCH_METHODDEF \
232 {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__},
233
234static wchar_t
235msvcrt_getwch_impl(PyModuleDef *module);
236
237static PyObject *
238msvcrt_getwch(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
239{
240 PyObject *return_value = NULL;
241 wchar_t _return_value;
242
243 _return_value = msvcrt_getwch_impl(module);
244 return_value = PyUnicode_FromOrdinal(_return_value);
245
246 return return_value;
247}
248
Zachary Ware45520892015-05-13 01:22:32 -0500249PyDoc_STRVAR(msvcrt_getche__doc__,
250"getche($module, /)\n"
251"--\n"
252"\n"
253"Similar to getch(), but the keypress will be echoed if possible.");
254
255#define MSVCRT_GETCHE_METHODDEF \
256 {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__},
257
258static int
259msvcrt_getche_impl(PyModuleDef *module);
260
261static PyObject *
262msvcrt_getche(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
263{
264 PyObject *return_value = NULL;
265 char s[1];
266
267 s[0] = msvcrt_getche_impl(module);
268 return_value = PyBytes_FromStringAndSize(s, 1);
269
270 return return_value;
271}
272
Zachary Ware45520892015-05-13 01:22:32 -0500273PyDoc_STRVAR(msvcrt_getwche__doc__,
274"getwche($module, /)\n"
275"--\n"
276"\n"
277"Wide char variant of getche(), returning a Unicode value.");
278
279#define MSVCRT_GETWCHE_METHODDEF \
280 {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__},
281
282static wchar_t
283msvcrt_getwche_impl(PyModuleDef *module);
284
285static PyObject *
286msvcrt_getwche(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
287{
288 PyObject *return_value = NULL;
289 wchar_t _return_value;
290
291 _return_value = msvcrt_getwche_impl(module);
292 return_value = PyUnicode_FromOrdinal(_return_value);
293
294 return return_value;
295}
296
Zachary Ware45520892015-05-13 01:22:32 -0500297PyDoc_STRVAR(msvcrt_putch__doc__,
298"putch($module, char, /)\n"
299"--\n"
300"\n"
301"Print the byte string char to the console without buffering.");
302
303#define MSVCRT_PUTCH_METHODDEF \
304 {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__},
305
306static PyObject *
307msvcrt_putch_impl(PyModuleDef *module, char char_value);
308
309static PyObject *
310msvcrt_putch(PyModuleDef *module, PyObject *arg)
311{
312 PyObject *return_value = NULL;
313 char char_value;
314
Zachary Ware77772c02015-05-13 10:58:35 -0500315 if (!PyArg_Parse(arg, "c:putch", &char_value))
Zachary Ware45520892015-05-13 01:22:32 -0500316 goto exit;
317 return_value = msvcrt_putch_impl(module, char_value);
318
319exit:
320 return return_value;
321}
322
Zachary Ware45520892015-05-13 01:22:32 -0500323PyDoc_STRVAR(msvcrt_putwch__doc__,
324"putwch($module, unicode_char, /)\n"
325"--\n"
326"\n"
327"Wide char variant of putch(), accepting a Unicode value.");
328
329#define MSVCRT_PUTWCH_METHODDEF \
330 {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__},
331
332static PyObject *
333msvcrt_putwch_impl(PyModuleDef *module, int unicode_char);
334
335static PyObject *
336msvcrt_putwch(PyModuleDef *module, PyObject *arg)
337{
338 PyObject *return_value = NULL;
339 int unicode_char;
340
Zachary Ware77772c02015-05-13 10:58:35 -0500341 if (!PyArg_Parse(arg, "C:putwch", &unicode_char))
Zachary Ware45520892015-05-13 01:22:32 -0500342 goto exit;
343 return_value = msvcrt_putwch_impl(module, unicode_char);
344
345exit:
346 return return_value;
347}
348
Zachary Ware45520892015-05-13 01:22:32 -0500349PyDoc_STRVAR(msvcrt_ungetch__doc__,
350"ungetch($module, char, /)\n"
351"--\n"
352"\n"
353"Opposite of getch.\n"
354"\n"
355"Cause the byte string char to be \"pushed back\" into the\n"
356"console buffer; it will be the next character read by\n"
357"getch() or getche().");
358
359#define MSVCRT_UNGETCH_METHODDEF \
360 {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__},
361
362static PyObject *
363msvcrt_ungetch_impl(PyModuleDef *module, char char_value);
364
365static PyObject *
366msvcrt_ungetch(PyModuleDef *module, PyObject *arg)
367{
368 PyObject *return_value = NULL;
369 char char_value;
370
Zachary Ware77772c02015-05-13 10:58:35 -0500371 if (!PyArg_Parse(arg, "c:ungetch", &char_value))
Zachary Ware45520892015-05-13 01:22:32 -0500372 goto exit;
373 return_value = msvcrt_ungetch_impl(module, char_value);
374
375exit:
376 return return_value;
377}
378
Zachary Ware45520892015-05-13 01:22:32 -0500379PyDoc_STRVAR(msvcrt_ungetwch__doc__,
380"ungetwch($module, unicode_char, /)\n"
381"--\n"
382"\n"
383"Wide char variant of ungetch(), accepting a Unicode value.");
384
385#define MSVCRT_UNGETWCH_METHODDEF \
386 {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__},
387
388static PyObject *
389msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char);
390
391static PyObject *
392msvcrt_ungetwch(PyModuleDef *module, PyObject *arg)
393{
394 PyObject *return_value = NULL;
395 int unicode_char;
396
Zachary Ware77772c02015-05-13 10:58:35 -0500397 if (!PyArg_Parse(arg, "C:ungetwch", &unicode_char))
Zachary Ware45520892015-05-13 01:22:32 -0500398 goto exit;
399 return_value = msvcrt_ungetwch_impl(module, unicode_char);
400
401exit:
402 return return_value;
403}
404
Zachary Ware45520892015-05-13 01:22:32 -0500405#if defined(_DEBUG)
406
407PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
408"CrtSetReportFile($module, type, file, /)\n"
409"--\n"
410"\n"
411"Wrapper around _CrtSetReportFile.\n"
412"\n"
413"Only available on Debug builds.");
414
415#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
416 {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_VARARGS, msvcrt_CrtSetReportFile__doc__},
417
418static long
419msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file);
420
421static PyObject *
422msvcrt_CrtSetReportFile(PyModuleDef *module, PyObject *args)
423{
424 PyObject *return_value = NULL;
425 int type;
426 int file;
427 long _return_value;
428
Zachary Ware77772c02015-05-13 10:58:35 -0500429 if (!PyArg_ParseTuple(args, "ii:CrtSetReportFile",
Zachary Ware45520892015-05-13 01:22:32 -0500430 &type, &file))
431 goto exit;
432 _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
433 if ((_return_value == -1) && PyErr_Occurred())
434 goto exit;
435 return_value = PyLong_FromLong(_return_value);
436
437exit:
438 return return_value;
439}
440
441#endif /* defined(_DEBUG) */
442
443#if defined(_DEBUG)
444
445PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__,
446"CrtSetReportMode($module, type, mode, /)\n"
447"--\n"
448"\n"
449"Wrapper around _CrtSetReportMode.\n"
450"\n"
451"Only available on Debug builds.");
452
453#define MSVCRT_CRTSETREPORTMODE_METHODDEF \
454 {"CrtSetReportMode", (PyCFunction)msvcrt_CrtSetReportMode, METH_VARARGS, msvcrt_CrtSetReportMode__doc__},
455
456static long
457msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode);
458
459static PyObject *
460msvcrt_CrtSetReportMode(PyModuleDef *module, PyObject *args)
461{
462 PyObject *return_value = NULL;
463 int type;
464 int mode;
465 long _return_value;
466
Zachary Ware77772c02015-05-13 10:58:35 -0500467 if (!PyArg_ParseTuple(args, "ii:CrtSetReportMode",
Zachary Ware45520892015-05-13 01:22:32 -0500468 &type, &mode))
469 goto exit;
470 _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode);
471 if ((_return_value == -1) && PyErr_Occurred())
472 goto exit;
473 return_value = PyLong_FromLong(_return_value);
474
475exit:
476 return return_value;
477}
478
479#endif /* defined(_DEBUG) */
480
481#if defined(_DEBUG)
482
483PyDoc_STRVAR(msvcrt_set_error_mode__doc__,
484"set_error_mode($module, mode, /)\n"
485"--\n"
486"\n"
487"Wrapper around _set_error_mode.\n"
488"\n"
489"Only available on Debug builds.");
490
491#define MSVCRT_SET_ERROR_MODE_METHODDEF \
492 {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__},
493
494static long
495msvcrt_set_error_mode_impl(PyModuleDef *module, int mode);
496
497static PyObject *
498msvcrt_set_error_mode(PyModuleDef *module, PyObject *arg)
499{
500 PyObject *return_value = NULL;
501 int mode;
502 long _return_value;
503
Zachary Ware77772c02015-05-13 10:58:35 -0500504 if (!PyArg_Parse(arg, "i:set_error_mode", &mode))
Zachary Ware45520892015-05-13 01:22:32 -0500505 goto exit;
506 _return_value = msvcrt_set_error_mode_impl(module, mode);
507 if ((_return_value == -1) && PyErr_Occurred())
508 goto exit;
509 return_value = PyLong_FromLong(_return_value);
510
511exit:
512 return return_value;
513}
514
515#endif /* defined(_DEBUG) */
516
517PyDoc_STRVAR(msvcrt_SetErrorMode__doc__,
518"SetErrorMode($module, mode, /)\n"
519"--\n"
520"\n"
521"Wrapper around SetErrorMode.");
522
523#define MSVCRT_SETERRORMODE_METHODDEF \
524 {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__},
525
526static PyObject *
527msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode);
528
529static PyObject *
530msvcrt_SetErrorMode(PyModuleDef *module, PyObject *arg)
531{
532 PyObject *return_value = NULL;
533 unsigned int mode;
534
Zachary Ware77772c02015-05-13 10:58:35 -0500535 if (!PyArg_Parse(arg, "I:SetErrorMode", &mode))
Zachary Ware45520892015-05-13 01:22:32 -0500536 goto exit;
537 return_value = msvcrt_SetErrorMode_impl(module, mode);
538
539exit:
540 return return_value;
541}
542
Zachary Ware45520892015-05-13 01:22:32 -0500543#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF
544 #define MSVCRT_CRTSETREPORTFILE_METHODDEF
545#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */
546
547#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF
548 #define MSVCRT_CRTSETREPORTMODE_METHODDEF
549#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */
550
551#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
552 #define MSVCRT_SET_ERROR_MODE_METHODDEF
553#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
Steve Dower71f574f2015-05-13 19:35:49 -0700554/*[clinic end generated code: output=16613d3119a1fd44 input=a9049054013a1b77]*/