Index: src/libfakechroot.c
===================================================================
--- src/libfakechroot.c	(revision 343)
+++ src/libfakechroot.c	(working copy)
@@ -113,6 +113,24 @@
                 } \
             } \
         } \
+        else \
+        { \
+            if (home_path!=NULL && *((char *)(path))=='~') { \
+                strcpy(fakechroot_buf, home_path); \
+                strcat(fakechroot_buf, &(path[1])); \
+                (path) = fakechroot_buf; \
+            } \
+            if (*((char *)(path)) != '/') { \
+                int len; \
+                if (next_getcwd == NULL) fakechroot_init(); \
+                next_getcwd(fakechroot_buf, FAKECHROOT_MAXPATH - strlen(path) - 1); \
+                len = strlen(fakechroot_buf); \
+                fakechroot_buf[len] = '/'; \
+                strcpy(fakechroot_buf + len + 1, (path)); \
+                narrow_chroot_path(fakechroot_buf, fakechroot_path, fakechroot_ptr); \
+                (path) = fakechroot_buf; \
+            } \
+        } \
     }
 
 #define expand_chroot_path_malloc(path, fakechroot_path, fakechroot_ptr, fakechroot_buf) \
@@ -134,6 +152,34 @@
                 } \
             } \
         } \
+        else \
+        { \
+            fakechroot_buf = NULL; \
+            if (home_path!=NULL && *((char *)(path))=='~') { \
+                if ((fakechroot_buf = malloc(strlen(home_path)+strlen(path))) == NULL) { \
+                    errno = ENOMEM; \
+                    return NULL; \
+                } \
+                strcpy(fakechroot_buf, home_path); \
+                strcat(fakechroot_buf, &(path[1])); \
+                (path) = fakechroot_buf; \
+            } \
+            if (*((char *)(path)) != '/') { \
+                int len = FAKECHROOT_MAXPATH; \
+                assert((path) != fakechroot_buf); \
+                if ((fakechroot_buf = malloc(FAKECHROOT_MAXPATH)) == NULL) { \
+                    errno = ENOMEM; \
+                    return NULL; \
+                } \
+                if (next_getcwd == NULL) fakechroot_init(); \
+                next_getcwd(fakechroot_buf, FAKECHROOT_MAXPATH - strlen(path) - 1); \
+                len = strlen(fakechroot_buf); \
+                fakechroot_buf[len] = '/'; \
+                strcpy(fakechroot_buf + len + 1, (path)); \
+                narrow_chroot_path(fakechroot_buf, fakechroot_path, fakechroot_ptr); \
+                (path) = fakechroot_buf; \
+            } \
+        } \
     }
 
 #define nextsym(function, name) \
@@ -845,7 +891,10 @@
     /* We need to expand relative paths */
     if (p_path[0] != '/') {
         if (next_getcwd == NULL) fakechroot_init();
-        next_getcwd(cwd_path, FAKECHROOT_MAXPATH);
+        next_getcwd(cwd_path, FAKECHROOT_MAXPATH - strlen(v_path) - 1);
+        len = strlen(cwd_path);
+        cwd_path[len] = '/';
+        strcpy(cwd_path + len + 1, v_path);
         v_path = cwd_path;
         narrow_chroot_path(v_path, fakechroot_path, fakechroot_ptr);
     }
