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 | |
---|
17 | static 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 | |
---|
36 | static PyMethodDef ptsname_methods[] = { |
---|
37 | { "ptsname", do_ptsname, METH_VARARGS }, |
---|
38 | { NULL } |
---|
39 | }; |
---|
40 | |
---|
41 | PyMODINIT_FUNC initptsname(void) |
---|
42 | { |
---|
43 | Py_InitModule("ptsname", ptsname_methods); |
---|
44 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.