source: trunk/packages/xen-3.1/xen-3.1/tools/python/ptsname/ptsname.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

File size: 870 bytes
Line 
1/******************************************************************************
2 * ptsname.c
3 *
4 * A python extension to expose the POSIX ptsname() function.
5 *
6 * Copyright (C) 2007 XenSource Ltd
7 */
8
9#include <Python.h>
10#include <stdlib.h>
11
12/* Needed for Python versions earlier than 2.3. */
13#ifndef PyMODINIT_FUNC
14#define PyMODINIT_FUNC DL_EXPORT(void)
15#endif
16
17static PyObject *do_ptsname(PyObject *self, PyObject *args)
18{
19    int fd;
20    char *path;
21
22    if (!PyArg_ParseTuple(args, "i", &fd))
23        return NULL;
24
25    path = ptsname(fd);
26
27    if (!path)
28    {
29        PyErr_SetFromErrno(PyExc_IOError);
30        return NULL;
31    } 
32
33    return PyString_FromString(path);
34}
35
36static PyMethodDef ptsname_methods[] = { 
37    { "ptsname", do_ptsname, METH_VARARGS }, 
38    { NULL }
39};
40
41PyMODINIT_FUNC initptsname(void)
42{
43    Py_InitModule("ptsname", ptsname_methods);
44}
Note: See TracBrowser for help on using the repository browser.