blob: 194304026c8828f5ffb66e4246d1838e9bd4c25a [file] [log] [blame]
Guido van Rossum86d25681992-05-15 11:05:54 +00001/***********************************************************
Guido van Rossum524b5881995-01-04 19:10:35 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossum86d25681992-05-15 11:05:54 +00004
5 All Rights Reserved
6
Guido van Rossumd266eb41996-10-25 14:44:06 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossum86d25681992-05-15 11:05:54 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000010both that copyright notice and this permission notice appear in
Guido van Rossum86d25681992-05-15 11:05:54 +000011supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000012Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
Guido van Rossum86d25681992-05-15 11:05:54 +000016
Guido van Rossumd266eb41996-10-25 14:44:06 +000017While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
Guido van Rossum86d25681992-05-15 11:05:54 +000029
30******************************************************************/
31
32/* SGI module -- random SGI-specific things */
33
Guido van Rossum55db5151996-12-10 00:32:31 +000034#include "Python.h"
Guido van Rossum86d25681992-05-15 11:05:54 +000035
Guido van Rossum43021931994-09-12 10:40:46 +000036#include <sys/types.h>
37#include <sys/stat.h>
38#include <unistd.h>
39#include <fcntl.h>
40
Guido van Rossum55db5151996-12-10 00:32:31 +000041static PyObject *
Guido van Rossum86d25681992-05-15 11:05:54 +000042sgi_nap(self, args)
Guido van Rossum55db5151996-12-10 00:32:31 +000043 PyObject *self;
44 PyObject *args;
Guido van Rossum86d25681992-05-15 11:05:54 +000045{
46 long ticks;
Guido van Rossum55db5151996-12-10 00:32:31 +000047 if (!PyArg_Parse(args, "l", &ticks))
Guido van Rossum86d25681992-05-15 11:05:54 +000048 return NULL;
Guido van Rossum55db5151996-12-10 00:32:31 +000049 Py_BEGIN_ALLOW_THREADS
Guido van Rossum86d25681992-05-15 11:05:54 +000050 sginap(ticks);
Guido van Rossum55db5151996-12-10 00:32:31 +000051 Py_END_ALLOW_THREADS
52 Py_INCREF(Py_None);
53 return Py_None;
Guido van Rossum86d25681992-05-15 11:05:54 +000054}
55
Guido van Rossum43021931994-09-12 10:40:46 +000056extern char *_getpty(int *, int, mode_t, int);
57
Guido van Rossum55db5151996-12-10 00:32:31 +000058static PyObject *
Guido van Rossum43021931994-09-12 10:40:46 +000059sgi__getpty(self, args)
Guido van Rossum55db5151996-12-10 00:32:31 +000060 PyObject *self;
61 PyObject *args;
Guido van Rossum43021931994-09-12 10:40:46 +000062{
63 int oflag;
64 int mode;
65 int nofork;
66 char *name;
67 int fildes;
Guido van Rossum55db5151996-12-10 00:32:31 +000068 if (!PyArg_Parse(args, "(iii)", &oflag, &mode, &nofork))
Guido van Rossum43021931994-09-12 10:40:46 +000069 return NULL;
70 errno = 0;
71 name = _getpty(&fildes, oflag, (mode_t)mode, nofork);
72 if (name == NULL) {
Guido van Rossum55db5151996-12-10 00:32:31 +000073 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum43021931994-09-12 10:40:46 +000074 return NULL;
75 }
Guido van Rossum55db5151996-12-10 00:32:31 +000076 return Py_BuildValue("(si)", name, fildes);
Guido van Rossum43021931994-09-12 10:40:46 +000077}
78
Guido van Rossum55db5151996-12-10 00:32:31 +000079static PyMethodDef sgi_methods[] = {
Guido van Rossum86d25681992-05-15 11:05:54 +000080 {"nap", sgi_nap},
Guido van Rossum43021931994-09-12 10:40:46 +000081 {"_getpty", sgi__getpty},
Guido van Rossum86d25681992-05-15 11:05:54 +000082 {NULL, NULL} /* sentinel */
83};
84
85
86void
87initsgi()
88{
Guido van Rossum55db5151996-12-10 00:32:31 +000089 Py_InitModule("sgi", sgi_methods);
Guido van Rossum86d25681992-05-15 11:05:54 +000090}