diff options
author | Jim Meyering <jim@meyering.net> | 1996-08-19 02:09:23 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-08-19 02:09:23 +0000 |
commit | 0ba429223da32aefd4ad32e0fd03a61e0a382b5e (patch) | |
tree | bb98fc537b3d722c93d612d32f626da3480f130e /src | |
parent | 7d234bb98e578e429a98978a0fc6bae7198d922c (diff) | |
download | coreutils-0ba429223da32aefd4ad32e0fd03a61e0a382b5e.tar.xz |
Include path-concat.h.
(do_copy): Check path_concat return value.
(path_concat): Remove function.
Diffstat (limited to 'src')
-rw-r--r-- | src/cp.c | 47 |
1 files changed, 9 insertions, 38 deletions
@@ -31,6 +31,7 @@ #include "cp.h" #include "backupfile.h" #include "argmatch.h" +#include "path-concat.h" #ifndef _POSIX_VERSION uid_t geteuid (); @@ -373,38 +374,6 @@ main (int argc, char **argv) exit (exit_status); } -/* Concatenate two pathname components, DIR and BASE, in newly-allocated - storage and return the result. Be careful that in the result they are - separated by a slash. That is, if DIR ends with a slash and BASE - begins with one, elide one slash at the end of DIR. If DIR doesn't end - with a slash and BASE doesn't begin with one, insert a slash between - them in the concatenation. Otherwise, simply concatenate DIR and BASE. - In any case, if BASE_IN_RESULT is non-NULL, set *BASE_IN_RESULT to point - to the copy of BASE in the returned concatenation. */ - -static char * -path_concat (const char *dir, const char *base, char **base_in_result) -{ - char *p; - char *p_concat; - - assert (strlen (dir) > 0); - p_concat = xmalloc (strlen (dir) + strlen (base) + 2); - p = stpcpy (p_concat, dir); - - if (*(p - 1) == '/' && *base == '/') - --p; - else if (*(p - 1) != '/' && *base != '/') - p = stpcpy (p, "/"); - - if (base_in_result) - *base_in_result = p; - - stpcpy (p, base); - - return p_concat; -} - /* Scan the arguments, and copy each by calling copy. Return 0 if successful, 1 if any errors occur. */ @@ -467,6 +436,8 @@ do_copy (int argc, char **argv) { /* Append all of `arg' to `dest'. */ dst_path = path_concat (dest, arg, &arg_in_concat); + if (dst_path == NULL) + error (1, 0, _("virtual memory exhausted")); /* For --parents, we have to make sure that the directory dirname (dst_path) exists. We may have to create a few @@ -535,12 +506,12 @@ do_copy (int argc, char **argv) && backup_type != none && STREQ (source, dest) && !new_dst && S_ISREG (sb.st_mode)) - { - backup_type = none; - new_dest = find_backup_file_name (dest); - if (new_dest == NULL) - error (1, 0, _("virtual memory exhausted")); - } + { + backup_type = none; + new_dest = find_backup_file_name (dest); + if (new_dest == NULL) + error (1, 0, _("virtual memory exhausted")); + } /* When the destination is specified with a trailing slash and the source exists but is not a directory, convert the user's command |