blob: 51923fc9c2249227ab94329bf52e79141b0c776f [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
225#if defined(_WCONIO_DEFINED)
226
227PyDoc_STRVAR(msvcrt_getwch__doc__,
228"getwch($module, /)\n"
229"--\n"
230"\n"
231"Wide char variant of getch(), returning a Unicode value.");
232
233#define MSVCRT_GETWCH_METHODDEF \
234 {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__},
235
236static wchar_t
237msvcrt_getwch_impl(PyModuleDef *module);
238
239static PyObject *
240msvcrt_getwch(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
241{
242 PyObject *return_value = NULL;
243 wchar_t _return_value;
244
245 _return_value = msvcrt_getwch_impl(module);
246 return_value = PyUnicode_FromOrdinal(_return_value);
247
248 return return_value;
249}
250
251#endif /* defined(_WCONIO_DEFINED) */
252
253PyDoc_STRVAR(msvcrt_getche__doc__,
254"getche($module, /)\n"
255"--\n"
256"\n"
257"Similar to getch(), but the keypress will be echoed if possible.");
258
259#define MSVCRT_GETCHE_METHODDEF \
260 {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__},
261
262static int
263msvcrt_getche_impl(PyModuleDef *module);
264
265static PyObject *
266msvcrt_getche(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
267{
268 PyObject *return_value = NULL;
269 char s[1];
270
271 s[0] = msvcrt_getche_impl(module);
272 return_value = PyBytes_FromStringAndSize(s, 1);
273
274 return return_value;
275}
276
277#if defined(_WCONIO_DEFINED)
278
279PyDoc_STRVAR(msvcrt_getwche__doc__,
280"getwche($module, /)\n"
281"--\n"
282"\n"
283"Wide char variant of getche(), returning a Unicode value.");
284
285#define MSVCRT_GETWCHE_METHODDEF \
286 {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__},
287
288static wchar_t
289msvcrt_getwche_impl(PyModuleDef *module);
290
291static PyObject *
292msvcrt_getwche(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
293{
294 PyObject *return_value = NULL;
295 wchar_t _return_value;
296
297 _return_value = msvcrt_getwche_impl(module);
298 return_value = PyUnicode_FromOrdinal(_return_value);
299
300 return return_value;
301}
302
303#endif /* defined(_WCONIO_DEFINED) */
304
305PyDoc_STRVAR(msvcrt_putch__doc__,
306"putch($module, char, /)\n"
307"--\n"
308"\n"
309"Print the byte string char to the console without buffering.");
310
311#define MSVCRT_PUTCH_METHODDEF \
312 {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__},
313
314static PyObject *
315msvcrt_putch_impl(PyModuleDef *module, char char_value);
316
317static PyObject *
318msvcrt_putch(PyModuleDef *module, PyObject *arg)
319{
320 PyObject *return_value = NULL;
321 char char_value;
322
Zachary Ware77772c02015-05-13 10:58:35 -0500323 if (!PyArg_Parse(arg, "c:putch", &char_value))
Zachary Ware45520892015-05-13 01:22:32 -0500324 goto exit;
325 return_value = msvcrt_putch_impl(module, char_value);
326
327exit:
328 return return_value;
329}
330
331#if defined(_WCONIO_DEFINED)
332
333PyDoc_STRVAR(msvcrt_putwch__doc__,
334"putwch($module, unicode_char, /)\n"
335"--\n"
336"\n"
337"Wide char variant of putch(), accepting a Unicode value.");
338
339#define MSVCRT_PUTWCH_METHODDEF \
340 {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__},
341
342static PyObject *
343msvcrt_putwch_impl(PyModuleDef *module, int unicode_char);
344
345static PyObject *
346msvcrt_putwch(PyModuleDef *module, PyObject *arg)
347{
348 PyObject *return_value = NULL;
349 int unicode_char;
350
Zachary Ware77772c02015-05-13 10:58:35 -0500351 if (!PyArg_Parse(arg, "C:putwch", &unicode_char))
Zachary Ware45520892015-05-13 01:22:32 -0500352 goto exit;
353 return_value = msvcrt_putwch_impl(module, unicode_char);
354
355exit:
356 return return_value;
357}
358
359#endif /* defined(_WCONIO_DEFINED) */
360
361PyDoc_STRVAR(msvcrt_ungetch__doc__,
362"ungetch($module, char, /)\n"
363"--\n"
364"\n"
365"Opposite of getch.\n"
366"\n"
367"Cause the byte string char to be \"pushed back\" into the\n"
368"console buffer; it will be the next character read by\n"
369"getch() or getche().");
370
371#define MSVCRT_UNGETCH_METHODDEF \
372 {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__},
373
374static PyObject *
375msvcrt_ungetch_impl(PyModuleDef *module, char char_value);
376
377static PyObject *
378msvcrt_ungetch(PyModuleDef *module, PyObject *arg)
379{
380 PyObject *return_value = NULL;
381 char char_value;
382
Zachary Ware77772c02015-05-13 10:58:35 -0500383 if (!PyArg_Parse(arg, "c:ungetch", &char_value))
Zachary Ware45520892015-05-13 01:22:32 -0500384 goto exit;
385 return_value = msvcrt_ungetch_impl(module, char_value);
386
387exit:
388 return return_value;
389}
390
391#if defined(_WCONIO_DEFINED)
392
393PyDoc_STRVAR(msvcrt_ungetwch__doc__,
394"ungetwch($module, unicode_char, /)\n"
395"--\n"
396"\n"
397"Wide char variant of ungetch(), accepting a Unicode value.");
398
399#define MSVCRT_UNGETWCH_METHODDEF \
400 {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__},
401
402static PyObject *
403msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char);
404
405static PyObject *
406msvcrt_ungetwch(PyModuleDef *module, PyObject *arg)
407{
408 PyObject *return_value = NULL;
409 int unicode_char;
410
Zachary Ware77772c02015-05-13 10:58:35 -0500411 if (!PyArg_Parse(arg, "C:ungetwch", &unicode_char))
Zachary Ware45520892015-05-13 01:22:32 -0500412 goto exit;
413 return_value = msvcrt_ungetwch_impl(module, unicode_char);
414
415exit:
416 return return_value;
417}
418
419#endif /* defined(_WCONIO_DEFINED) */
420
421#if defined(_DEBUG)
422
423PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
424"CrtSetReportFile($module, type, file, /)\n"
425"--\n"
426"\n"
427"Wrapper around _CrtSetReportFile.\n"
428"\n"
429"Only available on Debug builds.");
430
431#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
432 {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_VARARGS, msvcrt_CrtSetReportFile__doc__},
433
434static long
435msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file);
436
437static PyObject *
438msvcrt_CrtSetReportFile(PyModuleDef *module, PyObject *args)
439{
440 PyObject *return_value = NULL;
441 int type;
442 int file;
443 long _return_value;
444
Zachary Ware77772c02015-05-13 10:58:35 -0500445 if (!PyArg_ParseTuple(args, "ii:CrtSetReportFile",
Zachary Ware45520892015-05-13 01:22:32 -0500446 &type, &file))
447 goto exit;
448 _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
449 if ((_return_value == -1) && PyErr_Occurred())
450 goto exit;
451 return_value = PyLong_FromLong(_return_value);
452
453exit:
454 return return_value;
455}
456
457#endif /* defined(_DEBUG) */
458
459#if defined(_DEBUG)
460
461PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__,
462"CrtSetReportMode($module, type, mode, /)\n"
463"--\n"
464"\n"
465"Wrapper around _CrtSetReportMode.\n"
466"\n"
467"Only available on Debug builds.");
468
469#define MSVCRT_CRTSETREPORTMODE_METHODDEF \
470 {"CrtSetReportMode", (PyCFunction)msvcrt_CrtSetReportMode, METH_VARARGS, msvcrt_CrtSetReportMode__doc__},
471
472static long
473msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode);
474
475static PyObject *
476msvcrt_CrtSetReportMode(PyModuleDef *module, PyObject *args)
477{
478 PyObject *return_value = NULL;
479 int type;
480 int mode;
481 long _return_value;
482
Zachary Ware77772c02015-05-13 10:58:35 -0500483 if (!PyArg_ParseTuple(args, "ii:CrtSetReportMode",
Zachary Ware45520892015-05-13 01:22:32 -0500484 &type, &mode))
485 goto exit;
486 _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode);
487 if ((_return_value == -1) && PyErr_Occurred())
488 goto exit;
489 return_value = PyLong_FromLong(_return_value);
490
491exit:
492 return return_value;
493}
494
495#endif /* defined(_DEBUG) */
496
497#if defined(_DEBUG)
498
499PyDoc_STRVAR(msvcrt_set_error_mode__doc__,
500"set_error_mode($module, mode, /)\n"
501"--\n"
502"\n"
503"Wrapper around _set_error_mode.\n"
504"\n"
505"Only available on Debug builds.");
506
507#define MSVCRT_SET_ERROR_MODE_METHODDEF \
508 {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__},
509
510static long
511msvcrt_set_error_mode_impl(PyModuleDef *module, int mode);
512
513static PyObject *
514msvcrt_set_error_mode(PyModuleDef *module, PyObject *arg)
515{
516 PyObject *return_value = NULL;
517 int mode;
518 long _return_value;
519
Zachary Ware77772c02015-05-13 10:58:35 -0500520 if (!PyArg_Parse(arg, "i:set_error_mode", &mode))
Zachary Ware45520892015-05-13 01:22:32 -0500521 goto exit;
522 _return_value = msvcrt_set_error_mode_impl(module, mode);
523 if ((_return_value == -1) && PyErr_Occurred())
524 goto exit;
525 return_value = PyLong_FromLong(_return_value);
526
527exit:
528 return return_value;
529}
530
531#endif /* defined(_DEBUG) */
532
533PyDoc_STRVAR(msvcrt_SetErrorMode__doc__,
534"SetErrorMode($module, mode, /)\n"
535"--\n"
536"\n"
537"Wrapper around SetErrorMode.");
538
539#define MSVCRT_SETERRORMODE_METHODDEF \
540 {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__},
541
542static PyObject *
543msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode);
544
545static PyObject *
546msvcrt_SetErrorMode(PyModuleDef *module, PyObject *arg)
547{
548 PyObject *return_value = NULL;
549 unsigned int mode;
550
Zachary Ware77772c02015-05-13 10:58:35 -0500551 if (!PyArg_Parse(arg, "I:SetErrorMode", &mode))
Zachary Ware45520892015-05-13 01:22:32 -0500552 goto exit;
553 return_value = msvcrt_SetErrorMode_impl(module, mode);
554
555exit:
556 return return_value;
557}
558
559#ifndef MSVCRT_GETWCH_METHODDEF
560 #define MSVCRT_GETWCH_METHODDEF
561#endif /* !defined(MSVCRT_GETWCH_METHODDEF) */
562
563#ifndef MSVCRT_GETWCHE_METHODDEF
564 #define MSVCRT_GETWCHE_METHODDEF
565#endif /* !defined(MSVCRT_GETWCHE_METHODDEF) */
566
567#ifndef MSVCRT_PUTWCH_METHODDEF
568 #define MSVCRT_PUTWCH_METHODDEF
569#endif /* !defined(MSVCRT_PUTWCH_METHODDEF) */
570
571#ifndef MSVCRT_UNGETWCH_METHODDEF
572 #define MSVCRT_UNGETWCH_METHODDEF
573#endif /* !defined(MSVCRT_UNGETWCH_METHODDEF) */
574
575#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF
576 #define MSVCRT_CRTSETREPORTFILE_METHODDEF
577#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */
578
579#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF
580 #define MSVCRT_CRTSETREPORTMODE_METHODDEF
581#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */
582
583#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
584 #define MSVCRT_SET_ERROR_MODE_METHODDEF
585#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
Zachary Ware77772c02015-05-13 10:58:35 -0500586/*[clinic end generated code: output=72468bb32006a11b input=a9049054013a1b77]*/