diff --git a/configure.ac b/configure.ac
index e5109fff..e7c386d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,6 +293,9 @@ AC_CHECK_FUNCS([cfmakeraw fork setsid setpgid getpgid tcgetattr tcsetattr])
 AC_CHECK_FUNCS([pread pwrite])
 AC_CHECK_FUNCS([explicit_bzero])
 
+# Misc string routines.
+AC_CHECK_FUNCS([strchrnul])
+
 # for vtespawn
 AC_CHECK_HEADERS([sys/resource.h])
 AC_CHECK_FUNCS([fdwalk])
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 6876341d..d7cd03a8 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -31,6 +31,7 @@
 #include <vte/vte.h>
 #include "vteinternal.hh"
 #include "vtegtk.hh"
+#include "vteutils.h"
 #include "caps.h"
 #include "debug.h"
 
@@ -2534,7 +2535,7 @@ VteTerminalPrivate::set_current_hyperlink(char *hyperlink_params /* adopted */,
                 }
         }
         if (id) {
-                *strchrnul(id, ':') = '\0';
+                *_vte_strchrnul(id, ':') = '\0';
         }
         _vte_debug_print (VTE_DEBUG_HYPERLINK,
                           "OSC 8: id=\"%s\" uri=\"%s\"\n",
diff --git a/src/vtespawn.cc b/src/vtespawn.cc
index b411ca71..8830f3b1 100644
--- a/src/vtespawn.cc
+++ b/src/vtespawn.cc
@@ -39,6 +39,7 @@
 #include <glib-unix.h>
 
 #include "vtespawn.hh"
+#include "vteutils.h"
 #include "reaper.hh"
 
 #define VTE_SPAWN_ERROR_TIMED_OUT (G_SPAWN_ERROR_FAILED + 1000)
@@ -1001,16 +1002,6 @@ script_execute (const gchar *file,
   }
 }
 
-static gchar*
-my_strchrnul (const gchar *str, gchar c)
-{
-  gchar *p = (gchar*) str;
-  while (*p && (*p != c))
-    ++p;
-
-  return p;
-}
-
 static gint
 g_execute (const gchar *file,
            gchar      **argv,
@@ -1081,7 +1072,7 @@ g_execute (const gchar *file,
 	  char *startp;
 
 	  path = p;
-	  p = my_strchrnul (path, ':');
+	  p = _vte_strchrnul (path, ':');
 
 	  if (p == path)
 	    /* Two adjacent colons, or a colon at the beginning or the end
diff --git a/src/vteutils.cc b/src/vteutils.cc
index 648d1851..ae5463ba 100644
--- a/src/vteutils.cc
+++ b/src/vteutils.cc
@@ -19,12 +19,13 @@
 #include "config.h"
 
 #ifndef _GNU_SOURCE
-#define _GNU_SOURCE /* for O_TMPFILE */
+#define _GNU_SOURCE /* for O_TMPFILE and strchrnul */
 #endif
 
 #include "vteutils.h"
 
 #include <fcntl.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
 
@@ -96,3 +97,29 @@ _vte_mkstemp (void)
 
         return fd;
 }
+
+char *
+_vte_strchrnul (char *s, int c)
+{
+#ifdef HAVE_STRCHRNUL
+        return strchrnul (s, c);
+#else
+        while (*s && (*s != c))
+                ++s;
+
+        return s;
+#endif
+}
+
+const char *
+_vte_strchrnul (const char *s, int c)
+{
+#ifdef HAVE_STRCHRNUL
+        return strchrnul (s, c);
+#else
+        while (*s && (*s != c))
+                ++s;
+
+        return s;
+#endif
+}
diff --git a/src/vteutils.h b/src/vteutils.h
index 999e3bf9..6b83ce9d 100644
--- a/src/vteutils.h
+++ b/src/vteutils.h
@@ -24,6 +24,8 @@
 G_BEGIN_DECLS
 
 int _vte_mkstemp (void);
+extern "C++" char *_vte_strchrnul (char *s, int c);
+extern "C++" const char *_vte_strchrnul (const char *s, int c);
 
 G_END_DECLS
 
