aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/ptsname
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-03-05 18:54:26 +0000
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-03-05 18:54:26 +0000
commitd7ee1f5383acc25010251a9943dcd2485d60452a (patch)
tree4fa8e6d127e13d0eb35f21ca3ae6f7adcd8e196d /tools/python/ptsname
parentfb4f0a04214ab47b3eff2d05f0e0cfe33d7e00c5 (diff)
downloadxen-d7ee1f5383acc25010251a9943dcd2485d60452a.tar.gz
xen-d7ee1f5383acc25010251a9943dcd2485d60452a.tar.bz2
xen-d7ee1f5383acc25010251a9943dcd2485d60452a.zip
Move ptsname module under tools/python.
Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/python/ptsname')
-rw-r--r--tools/python/ptsname/ptsname.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/python/ptsname/ptsname.c b/tools/python/ptsname/ptsname.c
new file mode 100644
index 0000000000..3849bb8867
--- /dev/null
+++ b/tools/python/ptsname/ptsname.c
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * ptsname.c
+ *
+ * A python extension to expose the POSIX ptsname() function.
+ *
+ * Copyright (C) 2007 XenSource Ltd
+ */
+
+#include <Python.h>
+#include <stdlib.h>
+
+/* Needed for Python versions earlier than 2.3. */
+#ifndef PyMODINIT_FUNC
+#define PyMODINIT_FUNC DL_EXPORT(void)
+#endif
+
+static PyObject *do_ptsname(PyObject *self, PyObject *args)
+{
+ int fd;
+ char *path;
+
+ if (!PyArg_ParseTuple(args, "i", &fd))
+ return NULL;
+
+ path = ptsname(fd);
+
+ if (!path)
+ {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+
+ return PyString_FromString(path);
+}
+
+static PyMethodDef ptsname_methods[] = {
+ { "ptsname", do_ptsname, METH_VARARGS },
+ { NULL }
+};
+
+PyMODINIT_FUNC initptsname(void)
+{
+ Py_InitModule("ptsname", ptsname_methods);
+}