]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/_helpers.c
bup_stat bup_lstat: always treat path as binary
[bup.git] / lib / bup / _helpers.c
index f31fddb4c65e5e41604e390e35dd92f5cfa8e55a..592c1217d077ad3c9e5ae68b6ea517927c485a84 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;
@@ -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;