diff options
-rw-r--r-- | gnulib.modules | 1 | ||||
-rw-r--r-- | src/copypass.c | 23 |
2 files changed, 20 insertions, 4 deletions
diff --git a/gnulib.modules b/gnulib.modules index 335cd2a..002714b 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -27,3 +27,4 @@ unlocked-io utimens xalloc xalloc-die +xgetcwd diff --git a/src/copypass.c b/src/copypass.c index 1fcc8b3..5b1d594 100644 --- a/src/copypass.c +++ b/src/copypass.c @@ -27,6 +27,7 @@ #include "dstring.h" #include "extern.h" #include "paxlib.h" +#include "xgetcwd.h" #ifndef HAVE_LCHOWN # define lchown chown @@ -51,7 +52,7 @@ process_copy_pass () { dynamic_string input_name; /* Name of file from stdin. */ dynamic_string output_name; /* Name of new file. */ - int dirname_len; /* Length of `directory_name'. */ + size_t dirname_len; /* Length of `directory_name'. */ int res; /* Result of functions. */ char *slash; /* For moving past slashes in input name. */ struct stat in_file_stat; /* Stat record for input file. */ @@ -68,10 +69,24 @@ process_copy_pass () created files */ /* Initialize the copy pass. */ - dirname_len = strlen (directory_name); ds_init (&input_name, 128); - ds_init (&output_name, dirname_len + 2); - strcpy (output_name.ds_string, directory_name); + + dirname_len = strlen (directory_name); + if (change_directory_option && !ISSLASH (directory_name[0])) + { + char *pwd = xgetcwd (); + + dirname_len += strlen (pwd) + 1; + ds_init (&output_name, dirname_len + 2); + strcpy (output_name.ds_string, pwd); + strcat (output_name.ds_string, "/"); + strcat (output_name.ds_string, directory_name); + } + else + { + ds_init (&output_name, dirname_len + 2); + strcpy (output_name.ds_string, directory_name); + } output_name.ds_string[dirname_len] = '/'; output_is_seekable = true; |