Browse Source

When replacing strnlen, use a different name to prevent clashing with system strnlen if it does actually exist.

Jelmer Vernooij 13 years ago
parent
commit
58ac8a0c11
2 changed files with 7 additions and 6 deletions
  1. 3 0
      NEWS
  2. 4 6
      dulwich/_objects.c

+ 3 - 0
NEWS

@@ -35,6 +35,9 @@
  * Don't compile C extensions when running in pypy.
    (Ronny Pfannschmidt, #881546)
 
+ * Use different name for strnlen replacement function to avoid clashing
+   with system strnlen. (Jelmer Vernooij, #880362)
+
  API CHANGES
 
   * ``Repo.revision_history`` is now deprecated in favor of ``Repo.get_walker``.

+ 4 - 6
dulwich/_objects.c

@@ -21,20 +21,18 @@
 #include <stdlib.h>
 #include <sys/stat.h>
 
-#if defined(__APPLE__)
-#include <Availability.h>
-#endif
-
 #if (PY_VERSION_HEX < 0x02050000)
 typedef int Py_ssize_t;
 #endif
 
-#if defined(__MINGW32_VERSION) || (defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070) || (defined(_MSC_VER) && _MSC_VER < 1400)
-size_t strnlen(const char *text, size_t maxlen)
+#if defined(__MINGW32_VERSION) || defined(__APPLE__)
+size_t rep_strnlen(char *text, size_t maxlen);
+size_t rep_strnlen(char *text, size_t maxlen)
 {
 	const char *last = memchr(text, '\0', maxlen);
 	return last ? (size_t) (last - text) : maxlen;
 }
+#define strnlen rep_strnlen
 #endif
 
 #define bytehex(x) (((x)<0xa)?('0'+(x)):('a'-0xa+(x)))