--- common/common.h.orig
+++ common/common.h
@@ -26,6 +26,7 @@
 
 #include "osdep/compiler.h"
 #include "mpv_talloc.h"
+#include "common/compat.h"
 
 // double should be able to represent this exactly
 #define MP_NOPTS_VALUE (-0x1p+63)
--- /dev/null
+++ common/compat.h
@@ -0,0 +1,19 @@
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#include <stddef.h>
+#include <errno.h>
+
+static inline size_t strnlen(const char *s, size_t maxlen) {
+  int result = 0;
+
+  if (s != NULL) {
+    const char *iter = s;
+    while ((result < maxlen) && ((*(iter++)) != 0))
+      ++result;
+  }
+
+  return (result);
+}
+
+#endif /* !defined (COMPAT_H) */
--- ta/ta.h.orig
+++ ta/ta.h
@@ -20,6 +20,8 @@
 #include <stdbool.h>
 #include <stdarg.h>
 
+#include "common/compat.h"
+
 #ifdef __GNUC__
 #define TA_PRF(a1, a2) __attribute__ ((format(printf, a1, a2)))
 #define TA_TYPEOF(t) __typeof__(t)
