Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 1 | |
| 2 | /* SGI module -- random SGI-specific things */ |
| 3 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 6 | #include <sys/types.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <unistd.h> |
| 9 | #include <fcntl.h> |
| 10 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 11 | static PyObject * |
Peter Schneider-Kamp | 41c36ff | 2000-07-10 12:29:26 +0000 | [diff] [blame] | 12 | sgi_nap(PyObject *self, PyObject *args) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 13 | { |
| 14 | long ticks; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 15 | if (!PyArg_Parse(args, "l", &ticks)) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 16 | return NULL; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 17 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 18 | sginap(ticks); |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 19 | Py_END_ALLOW_THREADS |
| 20 | Py_INCREF(Py_None); |
| 21 | return Py_None; |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 24 | extern char *_getpty(int *, int, mode_t, int); |
| 25 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 26 | static PyObject * |
Peter Schneider-Kamp | 41c36ff | 2000-07-10 12:29:26 +0000 | [diff] [blame] | 27 | sgi__getpty(PyObject *self, PyObject *args) |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 28 | { |
| 29 | int oflag; |
| 30 | int mode; |
| 31 | int nofork; |
| 32 | char *name; |
| 33 | int fildes; |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 34 | if (!PyArg_Parse(args, "(iii)", &oflag, &mode, &nofork)) |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 35 | return NULL; |
| 36 | errno = 0; |
| 37 | name = _getpty(&fildes, oflag, (mode_t)mode, nofork); |
| 38 | if (name == NULL) { |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 39 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 40 | return NULL; |
| 41 | } |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 42 | return Py_BuildValue("(si)", name, fildes); |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 45 | static PyMethodDef sgi_methods[] = { |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 46 | {"nap", sgi_nap}, |
Guido van Rossum | 4302193 | 1994-09-12 10:40:46 +0000 | [diff] [blame] | 47 | {"_getpty", sgi__getpty}, |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 48 | {NULL, NULL} /* sentinel */ |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | void |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 53 | initsgi(void) |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 54 | { |
Guido van Rossum | 55db515 | 1996-12-10 00:32:31 +0000 | [diff] [blame] | 55 | Py_InitModule("sgi", sgi_methods); |
Guido van Rossum | 86d2568 | 1992-05-15 11:05:54 +0000 | [diff] [blame] | 56 | } |