diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-09-23 11:09:19 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-09-23 11:09:19 +0300 |
commit | 79e87e5ea16ed7118536b12e267d93db74e15265 (patch) | |
tree | 19a9e5a20992926fa213c9133c7dc5e952a55c89 /python/rpmfd-py.c | |
parent | 6b9adb71f9715de3648673ae6ca4475a9e98d141 (diff) | |
download | rpm-79e87e5ea16ed7118536b12e267d93db74e15265.tar.gz rpm-79e87e5ea16ed7118536b12e267d93db74e15265.tar.bz2 rpm-79e87e5ea16ed7118536b12e267d93db74e15265.zip |
Add helper to convert python file objects to rpmio FD_t type
Diffstat (limited to 'python/rpmfd-py.c')
-rw-r--r-- | python/rpmfd-py.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c new file mode 100644 index 000000000..2deb06793 --- /dev/null +++ b/python/rpmfd-py.c @@ -0,0 +1,22 @@ + +#include "rpmsystem-py.h" +#include "rpmfd-py.h" + +FD_t rpmFdFromPyObject(PyObject *obj) +{ + FD_t fd = NULL; + + if (PyInt_Check(obj)) { + fd = fdDup(PyInt_AsLong(obj)); + } else if (PyFile_Check(obj)) { + FILE *fp = PyFile_AsFile(obj); + fd = fdDup(fileno(fp)); + } else { + PyErr_SetString(PyExc_TypeError, "integer or file object expected"); + return NULL; + } + if (fd == NULL || Ferror(fd)) { + PyErr_SetFromErrno(PyExc_IOError); + } + return fd; +} |