]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/_helpers.c
txstat: fix for python 3
[bup.git] / lib / bup / _helpers.c
index f31fddb4c65e5e41604e390e35dd92f5cfa8e55a..9078be3da723d8e7757662950a7521bdc275754f 100644 (file)
@@ -29,6 +29,9 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
 
 #ifdef HAVE_LINUX_FS_H
 #include <linux/fs.h>
@@ -71,10 +74,10 @@ typedef struct {
 #if PY_MAJOR_VERSION < 3
 static state_t state;
 #  define get_state(x) (&state)
-#  define buf_argf "s"
+#  define cstr_argf "s"
 #else
 #  define get_state(x) ((state_t *) PyModule_GetState(x))
-#  define buf_argf "y"
+#  define cstr_argf "y"
 #endif // PY_MAJOR_VERSION >= 3
 
 
@@ -742,6 +745,11 @@ struct sha {
     unsigned char bytes[20];
 };
 
+static inline int _cmp_sha(const struct sha *sha1, const struct sha *sha2)
+{
+    return memcmp(sha1->bytes, sha2->bytes, sizeof(sha1->bytes));
+}
+
 
 struct idx {
     unsigned char *map;
@@ -752,17 +760,6 @@ struct idx {
     int name_base;
 };
 
-
-static int _cmp_sha(const struct sha *sha1, const struct sha *sha2)
-{
-    int i;
-    for (i = 0; i < sizeof(struct sha); i++)
-       if (sha1->bytes[i] != sha2->bytes[i])
-           return sha1->bytes[i] - sha2->bytes[i];
-    return 0;
-}
-
-
 static void _fix_idx_order(struct idx **idxs, int *last_i)
 {
     struct idx *idx;
@@ -1253,7 +1250,7 @@ static PyObject *bup_utimensat(PyObject *self, PyObject *args)
     PyObject *access_py, *modification_py;
     struct timespec ts[2];
 
-    if (!PyArg_ParseTuple(args, "is((Ol)(Ol))i",
+    if (!PyArg_ParseTuple(args, "i" cstr_argf "((Ol)(Ol))i",
                           &fd,
                           &path,
                           &access_py, &(ts[0].tv_nsec),
@@ -1295,7 +1292,7 @@ static int bup_parse_xutimes_args(char **path,
     PyObject *access_py, *modification_py;
     long long access_us, modification_us; // POSIX guarantees tv_usec is signed.
 
-    if (!PyArg_ParseTuple(args, "s((OL)(OL))",
+    if (!PyArg_ParseTuple(args, cstr_argf "((OL)(OL))",
                           path,
                           &access_py, &access_us,
                           &modification_py, &modification_us))
@@ -1411,7 +1408,7 @@ static PyObject *bup_stat(PyObject *self, PyObject *args)
     int rc;
     char *filename;
 
-    if (!PyArg_ParseTuple(args, "s", &filename))
+    if (!PyArg_ParseTuple(args, cstr_argf, &filename))
         return NULL;
 
     struct stat st;
@@ -1427,7 +1424,7 @@ static PyObject *bup_lstat(PyObject *self, PyObject *args)
     int rc;
     char *filename;
 
-    if (!PyArg_ParseTuple(args, "s", &filename))
+    if (!PyArg_ParseTuple(args, cstr_argf, &filename))
         return NULL;
 
     struct stat st;
@@ -1484,7 +1481,7 @@ static PyObject *bup_mincore(PyObject *self, PyObject *args)
     Py_buffer src, dest;
     PyObject *py_src_n, *py_src_off, *py_dest_off;
 
-    if (!PyArg_ParseTuple(args, buf_argf "*OOw*O",
+    if (!PyArg_ParseTuple(args, cstr_argf "*OOw*O",
                           &src, &py_src_n, &py_src_off,
                           &dest, &py_dest_off))
        return NULL;