diff --git a/pd/src/s_main.c b/pd/src/s_main.c
index 23318379e4b38403eef38e0a3ec941e8c523860a..8c9b52a2ebda360267fa2459784d4d638980ef47 100644
--- a/pd/src/s_main.c
+++ b/pd/src/s_main.c
@@ -459,6 +459,14 @@ void sys_findprogdir(char *progname)
             /* go back to the parent from there, e.g., ~/pd */
         lastslash = strrchr(sbuf, '/');
         if (lastslash)
+        {
+            strncpy(sbuf2, sbuf, lastslash-sbuf);
+            sbuf2[lastslash-sbuf] = 0;
+        }
+            /* go back to the parent from there once more, e.g., ~/pd */
+		strcpy(sbuf, sbuf2);
+        lastslash = strrchr(sbuf, '/');
+        if (lastslash)
         {
             strncpy(sbuf2, sbuf, lastslash-sbuf);
             sbuf2[lastslash-sbuf] = 0;