Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
| 11 | /* SGI module -- random SGI-specific things */ |
| 12 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 13 | #include "Python.h" |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 14 | |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | #include <unistd.h> |
| 18 | #include <fcntl.h> |
| 19 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 20 | static PyObject * |
Peter Schneider-Kamp | 41c36ff | 2000-07-10 12:29:26 +0000 | [diff] [blame] | 21 | sgi_nap(PyObject *self, PyObject *args) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 22 | { |
| 23 | long ticks; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 24 | if (!PyArg_Parse(args, "l", &ticks)) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 25 | return NULL; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 26 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 27 | sginap(ticks); |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 28 | Py_END_ALLOW_THREADS |
| 29 | Py_INCREF(Py_None); |
| 30 | return Py_None; |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 33 | extern char *_getpty(int *, int, mode_t, int); |
| 34 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 35 | static PyObject * |
Peter Schneider-Kamp | 41c36ff | 2000-07-10 12:29:26 +0000 | [diff] [blame] | 36 | sgi__getpty(PyObject *self, PyObject *args) |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 37 | { |
| 38 | int oflag; |
| 39 | int mode; |
| 40 | int nofork; |
| 41 | char *name; |
| 42 | int fildes; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 43 | if (!PyArg_Parse(args, "(iii)", &oflag, &mode, &nofork)) |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 44 | return NULL; |
| 45 | errno = 0; |
| 46 | name = _getpty(&fildes, oflag, (mode_t)mode, nofork); |
| 47 | if (name == NULL) { |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 48 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 49 | return NULL; |
| 50 | } |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 51 | return Py_BuildValue("(si)", name, fildes); |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 54 | static PyMethodDef sgi_methods[] = { |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 55 | {"nap", sgi_nap}, |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 56 | {"_getpty", sgi__getpty}, |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 57 | {NULL, NULL} /* sentinel */ |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | void |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame^] | 62 | initsgi(void) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 63 | { |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 64 | Py_InitModule("sgi", sgi_methods); |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 65 | } |