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..3ccfb9d6 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -18,6 +18,10 @@
 
 #include "config.h"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* for strchrnul */
+#endif
+
 #include <search.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +35,7 @@
 #include <vte/vte.h>
 #include "vteinternal.hh"
 #include "vtegtk.hh"
+#include "vteutils.h" /* for strchrnul on non-GNU systems */
 #include "caps.h"
 #include "debug.h"
 
diff --git a/src/vtespawn.cc b/src/vtespawn.cc
index b411ca71..fb6b48e2 100644
--- a/src/vtespawn.cc
+++ b/src/vtespawn.cc
@@ -22,6 +22,10 @@
 
 #include "config.h"
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* for strchrnul */
+#endif
+
 #include <sys/time.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -39,6 +43,7 @@
 #include <glib-unix.h>
 
 #include "vtespawn.hh"
+#include "vteutils.h" /* for strchrnul on non-GNU systems */
 #include "reaper.hh"
 
 #define VTE_SPAWN_ERROR_TIMED_OUT (G_SPAWN_ERROR_FAILED + 1000)
@@ -1001,16 +1006,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 +1076,7 @@ g_execute (const gchar *file,
 	  char *startp;
 
 	  path = p;
-	  p = my_strchrnul (path, ':');
+	  p = 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..37e0692a 100644
--- a/src/vteutils.cc
+++ b/src/vteutils.cc
@@ -96,3 +96,16 @@ _vte_mkstemp (void)
 
         return fd;
 }
+
+#ifndef HAVE_STRCHRNUL
+/* Copeid from glib */
+char *
+strchrnul (const char *s, int c)
+{
+        char *p = (char *) s;
+        while (*p && (*p != c))
+                ++p;
+
+        return p;
+}
+#endif /* !HAVE_STRCHRNUL */
diff --git a/src/vteutils.h b/src/vteutils.h
index 999e3bf9..0cc98eb2 100644
--- a/src/vteutils.h
+++ b/src/vteutils.h
@@ -24,6 +24,9 @@
 G_BEGIN_DECLS
 
 int _vte_mkstemp (void);
+#ifndef HAVE_STRCHRNUL
+char *strchrnul (const char *s, int c);
+#endif
 
 G_END_DECLS
 
