diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-12-02 21:44:07 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-12-02 21:44:07 +0000 |
commit | e4b3fbe16e44403b80ecc2e01732cbbbc9c47929 (patch) | |
tree | e5f3cdbb8d72e1a0d9744a75eb5df177ebe10747 /_obnammodule.c | |
parent | 4a390d5cb91f97e21de95018a28b39d84a5cf647 (diff) | |
download | obnam-e4b3fbe16e44403b80ecc2e01732cbbbc9c47929.tar.gz |
add lgetxattr wrapper
Diffstat (limited to '_obnammodule.c')
-rw-r--r-- | _obnammodule.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/_obnammodule.c b/_obnammodule.c index 1515fef9..f124b394 100644 --- a/_obnammodule.c +++ b/_obnammodule.c @@ -142,7 +142,7 @@ llistxattr_wrapper(PyObject *self, PyObject *args) char *buf = malloc(bufsize); ssize_t n = llistxattr(filename, buf, bufsize); - if (n >= 0) + if (n > 0) o = Py_BuildValue("s#", buf, (int) n); else if (n == -1 && errno != ERANGE) o = Py_BuildValue("i", errno); @@ -156,7 +156,29 @@ llistxattr_wrapper(PyObject *self, PyObject *args) static PyObject * lgetxattr_wrapper(PyObject *self, PyObject *args) { - return NULL; + const char *filename; + const char *attrname; + size_t bufsize; + PyObject *o; + + if (!PyArg_ParseTuple(args, "ss", &filename, &attrname)) + return NULL; + + bufsize = 0; + o = NULL; + do { + bufsize += 1024; + char *buf = malloc(bufsize); + ssize_t n = lgetxattr(filename, attrname, buf, bufsize); + + if (n > 0) + o = Py_BuildValue("s#", buf, (int) n); + else if (n == -1 && errno != ERANGE) + o = Py_BuildValue("i", errno); + free(buf); + } while (o == NULL); + + return o; } @@ -176,9 +198,9 @@ static PyMethodDef methods[] = { "lstat(2) wrapper; arg is filename, returns tuple."}, {"llistxattr", llistxattr_wrapper, METH_VARARGS, "llistxattr(2) wrapper; arg is filename, returns tuple."}, - {"lgetxattrs", lgetxattr_wrapper, METH_VARARGS, + {"lgetxattr", lgetxattr_wrapper, METH_VARARGS, "lgetxattr(2) wrapper; arg is filename, returns tuple."}, - {"lsetxattrs", lsetxattr_wrapper, METH_VARARGS, + {"lsetxattr", lsetxattr_wrapper, METH_VARARGS, "lsetxattr(2) wrapper; arg is filename, returns errno."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; |