X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Fcopy.c;h=2aa7c0a11ab0938fdc6fc6ecb0d896a3affa0039;hb=b8be128caa27fa5e1636e9e4caff3e23a6dc761f;hp=789e430d177ba72bd28169ce2bd250e9b0cd77b8;hpb=2635a9c70e5f8aab85bbcb6b7a645f720d1e4466;p=libguestfs.git diff --git a/fish/copy.c b/fish/copy.c index 789e430..2aa7c0a 100644 --- a/fish/copy.c +++ b/fish/copy.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,10 +31,10 @@ static int make_tar_from_local (const char *local); static int make_tar_output (const char *local, const char *basename); -static int split_path (char *buf, size_t buf_size, const char *path, char **dirname, char **basename); +static int split_path (char *buf, size_t buf_size, const char *path, const char **dirname, const char **basename); int -do_copy_in (const char *cmd, int argc, char *argv[]) +run_copy_in (const char *cmd, size_t argc, char *argv[]) { if (argc < 2) { fprintf (stderr, @@ -119,7 +119,7 @@ make_tar_from_local (const char *local) close (fd[1]); char buf[PATH_MAX]; - char *dirname, *basename; + const char *dirname, *basename; if (split_path (buf, sizeof buf, local, &dirname, &basename) == -1) _exit (EXIT_FAILURE); @@ -132,7 +132,7 @@ make_tar_from_local (const char *local) */ static int split_path (char *buf, size_t buf_size, - const char *path, char **dirname, char **basename) + const char *path, const char **dirname, const char **basename) { size_t len = strlen (path); if (len == 0 || len > buf_size - 1) { @@ -148,11 +148,14 @@ split_path (char *buf, size_t buf_size, } char *p = strrchr (buf, '/'); - if (p && p > buf) { + if (p && p > buf) { /* "foo/bar" */ *p = '\0'; p++; if (dirname) *dirname = buf; if (basename) *basename = p; + } else if (p && p == buf) { /* "/foo" */ + if (dirname) *dirname = "/"; + if (basename) *basename = buf+1; } else { if (dirname) *dirname = NULL; if (basename) *basename = buf; @@ -174,7 +177,7 @@ tar_create (const char *dir, const char *path) } int -do_copy_out (const char *cmd, int argc, char *argv[]) +run_copy_out (const char *cmd, size_t argc, char *argv[]) { if (argc < 2) { fprintf (stderr, @@ -189,7 +192,7 @@ do_copy_out (const char *cmd, int argc, char *argv[]) struct stat statbuf; if (stat (local, &statbuf) == -1 || ! (S_ISDIR (statbuf.st_mode))) { - fprintf (stderr, _("copy-in: target '%s' is not a directory\n"), local); + fprintf (stderr, _("copy-out: target '%s' is not a directory\n"), local); return -1; } @@ -204,7 +207,7 @@ do_copy_out (const char *cmd, int argc, char *argv[]) return -1; if (r == 1) { /* is file */ char buf[PATH_MAX]; - char *basename; + const char *basename; if (split_path (buf, sizeof buf, argv[i], NULL, &basename) == -1) return -1; @@ -225,7 +228,7 @@ do_copy_out (const char *cmd, int argc, char *argv[]) } char buf[PATH_MAX]; - char *basename; + const char *basename; if (split_path (buf, sizeof buf, argv[i], NULL, &basename) == -1) return -1;