aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-07-23 10:57:11 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-07-23 10:57:11 +0300
commit6377e0dfecb9836aabca5d11f2dcfa7d722115af (patch)
tree09faa54213cee5283daff7750543f68f777bc4f0
parent3ac72b91f69c1cdfb61babb1ae3dbc69e2065eac (diff)
downloadcpio-6377e0dfecb9836aabca5d11f2dcfa7d722115af.tar.gz
cpio-6377e0dfecb9836aabca5d11f2dcfa7d722115af.tar.bz2
Improve handling of -D in copy-pass mode.
* gnulib.modules: Add xgetcwd. * src/copypass.c (process_copy_pass): Convert directory_name to absolute if -D option was given.
-rw-r--r--gnulib.modules1
-rw-r--r--src/copypass.c23
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;

Return to:

Send suggestions and report system problems to the System administrator.