diff --git a/src/core/utils.c b/src/core/utils.c
index e42b0ba..0da3cd6 100644
--- a/src/core/utils.c
+++ b/src/core/utils.c
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <string.h>             /*for SIGTERM */
 #include <math.h>
+#include <ctype.h>
 #include <fontconfig/fontconfig.h>
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
@@ -2796,6 +2800,7 @@ get_executable_dir ()
   if(dir == NULL)
   {
     char path[1024];
+    int n;
 
 #ifdef G_OS_WIN32
     GetModuleFileNameW(NULL, path, MAX_PATH);
@@ -2805,7 +2810,12 @@ get_executable_dir ()
     _NSGetExecutablePath (path, &size);
 
 #else
-   readlink("/proc/self/exe", path, sizeof(path));
+   if ((n=readlink("/proc/self/exe", path, sizeof(path))) < 0)
+   {
+	perror("/proc/self/exe");
+	exit (1);
+   }
+   path[n] = 0;
 
 #endif
     dir = g_path_get_dirname(path);
