home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / sgimodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  1001 b   |  57 lines

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