From: Panu Matilainen Date: Wed, 23 Sep 2009 08:09:19 +0000 (+0300) Subject: Add helper to convert python file objects to rpmio FD_t type X-Git-Tag: rpm-4.8.0-beta1~204 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79e87e5ea16ed7118536b12e267d93db74e15265;p=platform%2Fupstream%2Frpm.git Add helper to convert python file objects to rpmio FD_t type --- diff --git a/python/Makefile.am b/python/Makefile.am index 6f324e4..8d763ed 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -21,6 +21,7 @@ _rpmmodule_la_LIBADD = \ _rpmmodule_la_SOURCES = rpmmodule.c rpmsystem-py.h \ header-py.c header-py.h \ rpmds-py.c rpmds-py.h \ + rpmfd-py.c rpmfd-py.h \ rpmfi-py.c rpmfi-py.h \ rpmmi-py.c rpmmi-py.h \ rpmps-py.c rpmps-py.h \ diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c new file mode 100644 index 0000000..2deb067 --- /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; +} diff --git a/python/rpmfd-py.h b/python/rpmfd-py.h new file mode 100644 index 0000000..2c7a51c --- /dev/null +++ b/python/rpmfd-py.h @@ -0,0 +1,8 @@ +#ifndef H_RPMFD_PY +#define H_RPMFD_PY + +#include + +FD_t rpmFdFromPyObject(PyObject *obj); + +#endif