diff options
author | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-03-05 18:54:26 +0000 |
---|---|---|
committer | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-03-05 18:54:26 +0000 |
commit | d7ee1f5383acc25010251a9943dcd2485d60452a (patch) | |
tree | 4fa8e6d127e13d0eb35f21ca3ae6f7adcd8e196d /tools/python/ptsname | |
parent | fb4f0a04214ab47b3eff2d05f0e0cfe33d7e00c5 (diff) | |
download | xen-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.c | 44 |
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); +} |