diff --git a/Makefile b/Makefile
index 3535b6dfa6..16ca59bbaa 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ include config.mk
TARGET = ssnes tools/ssnes-joyconfig
-OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o
+OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o strl.o
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
HEADERS = $(wildcard */*.h) $(wildcard *.h)
@@ -119,6 +119,10 @@ else
LIBS += $(libsnes)
endif
+ifeq ($(HAVE_STRL), 1)
+ DEFINES += -DHAVE_STRL
+endif
+
ifneq ($(V),1)
Q := @
endif
diff --git a/Makefile.win32 b/Makefile.win32
index 27c310ba5a..236575a3ae 100644
--- a/Makefile.win32
+++ b/Makefile.win32
@@ -1,6 +1,6 @@
TARGET = ssnes.exe
JTARGET = ssnes-joyconfig.exe
-OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o
+OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o strl.o
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
CC = gcc
diff --git a/qb/config.libs.sh b/qb/config.libs.sh
index 1f293a5765..e5d6622435 100644
--- a/qb/config.libs.sh
+++ b/qb/config.libs.sh
@@ -61,8 +61,10 @@ check_lib DYNAMIC -ldl dlopen
check_pkgconf FREETYPE freetype2
check_lib XVIDEO -lXv XvShmCreateImage
+check_lib STRL -lc strlcpy
+
# Creates config.mk and config.h.
-VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO"
+VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL"
create_config_make config.mk $VARS
create_config_header config.h $VARS
diff --git a/strl.c b/strl.c
new file mode 100644
index 0000000000..13600bda40
--- /dev/null
+++ b/strl.c
@@ -0,0 +1,47 @@
+/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
+ * Copyright (C) 2010-2011 - Hans-Kristian Arntzen
+ *
+ * Some code herein may be based on code found in BSNES.
+ *
+ * SSNES is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with SSNES.
+ * If not, see .
+ */
+
+#include "strl.h"
+
+#ifndef HAVE_STRL
+// Implementation of strlcpy()/strlcat() based on OpenBSD.
+
+size_t strlcpy(char *dest, const char *source, size_t size)
+{
+ size_t src_size = 0;
+ size_t n = size;
+
+ if (n)
+ while (--n && (*dest++ = *source++)) src_size++;
+
+ if (!n)
+ {
+ if (size) *dest = '\0';
+ while (*source++) src_size++;
+ }
+
+ return src_size;
+}
+
+size_t strlcat(char *dest, const char *source, size_t size)
+{
+ size_t len = strlen(dest);
+ dest += len;
+ size -= len;
+ return len + strlcpy(dest, source, size);
+}
+#endif
diff --git a/strl.h b/strl.h
new file mode 100644
index 0000000000..c51f673c7f
--- /dev/null
+++ b/strl.h
@@ -0,0 +1,35 @@
+/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
+ * Copyright (C) 2010-2011 - Hans-Kristian Arntzen
+ *
+ * Some code herein may be based on code found in BSNES.
+ *
+ * SSNES is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with SSNES.
+ * If not, see .
+ */
+
+#ifndef __SSNES_STRL_H
+#define __SSNES_STRL_H
+
+#include
+#include
+#include "config.h"
+
+#ifndef HAVE_STRL
+// Avoid possible naming collitions during link since we prefer to use the actual name.
+#define strlcpy(dst, src, size) __strlcpy_ssnes(dst, src, size)
+#define strlcat(dst, src, size) __strlcat_ssnes(dst, src, size)
+
+size_t strlcpy(char *dest, const char *source, size_t size);
+size_t strlcat(char *dest, const char *source, size_t size);
+#endif
+
+#endif
+