Browse Source

Provide strnlen() on mingw32 which doesn't have it.

Hans Kolek 14 years ago
parent
commit
ca9a68de53
2 changed files with 10 additions and 0 deletions
  1. 2 0
      NEWS
  2. 8 0
      dulwich/_objects.c

+ 2 - 0
NEWS

@@ -9,6 +9,8 @@
   * ThinPackData.from_file now works with resolve_ext_ref callback.
     (Dave Borowitz)
 
+  * Provide strnlen() on mingw32 which doesn't have it. (Hans Kolek)
+
  FEATURES
 
   * Use slots for core objects to save up on memory. (Jelmer Vernooij)

+ 8 - 0
dulwich/_objects.c

@@ -25,6 +25,14 @@
 typedef int Py_ssize_t;
 #endif
 
+#ifdef __MINGW32_VERSION
+size_t strnlen(char *text, size_t maxlen)
+{
+	const char *last = memchr(text, '\0', maxlen);
+	return last ? (size_t) (last - text) : maxlen;
+}
+#endif
+
 #define bytehex(x) (((x)<0xa)?('0'+(x)):('a'-0xa+(x)))
 
 static PyObject *sha_to_pyhex(const unsigned char *sha)