History log of /netbsd-current/bin/cp/cp.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.63 07-Jun-2024 andvar

s/concatentation/concatenation/ in comment.


Revision tags: netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.62 22-May-2020 christos

fix reversed test.


# 1.61 17-May-2020 christos

No ACL support for install media (SMALLPROG)


# 1.60 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


Revision tags: netbsd-8-3-RELEASE netbsd-9-4-RELEASE netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.59 05-Mar-2016 uwe

branches: 1.59.16;
The '-i' flag should work regardless of whether the standard input is
a terminal. The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense. Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-7-base yamt-pagecache-base9 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 tls-maxphys-base matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base
# 1.58 04-Jan-2012 christos

branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 03-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.55 06-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


Revision tags: matt-mips64-premerge-20101231
# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


Revision tags: matt-premerge-20091211
# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE jym-xensuspend-nbase netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 jym-xensuspend-base netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.51 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 wrstuden-revivesa-base
# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.48 26-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


Revision tags: abandoned-netbsd-4-base
# 1.44 16-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 15-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 17-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 24-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-3-base netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


Revision tags: fvdl_fs64_base
# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 07-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 03-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


Revision tags: netbsd-1-5-base minoura-xpg4dl-base wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.28 05-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 25-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 19-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 28-Jul-1998 mycroft

Delint.


# 1.21 28-Jul-1998 mycroft

Delint.


# 1.20 28-Jul-1998 mycroft

Delint.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 20-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 19-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 09-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 02-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 26-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.9 28-Mar-1994 cgd

no more MAP_FILE


# 1.8 25-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 07-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.62 22-May-2020 christos

fix reversed test.


# 1.61 17-May-2020 christos

No ACL support for install media (SMALLPROG)


# 1.60 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.59 05-Mar-2016 uwe

branches: 1.59.16;
The '-i' flag should work regardless of whether the standard input is
a terminal. The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense. Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-7-base yamt-pagecache-base9 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 tls-maxphys-base matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base
# 1.58 04-Jan-2012 christos

branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 03-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.55 06-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


Revision tags: matt-mips64-premerge-20101231
# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


Revision tags: matt-premerge-20091211
# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE jym-xensuspend-nbase netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 jym-xensuspend-base netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.51 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 wrstuden-revivesa-base
# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.48 26-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


Revision tags: abandoned-netbsd-4-base
# 1.44 16-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 15-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 17-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 24-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-3-base netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


Revision tags: fvdl_fs64_base
# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 07-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 03-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


Revision tags: netbsd-1-5-base minoura-xpg4dl-base wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.28 05-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 25-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 19-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 28-Jul-1998 mycroft

Delint.


# 1.21 28-Jul-1998 mycroft

Delint.


# 1.20 28-Jul-1998 mycroft

Delint.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 20-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 19-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 09-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 02-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 26-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.9 28-Mar-1994 cgd

no more MAP_FILE


# 1.8 25-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 07-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.61 17-May-2020 christos

No ACL support for install media (SMALLPROG)


# 1.60 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.59 05-Mar-2016 uwe

branches: 1.59.16;
The '-i' flag should work regardless of whether the standard input is
a terminal. The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense. Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-7-base yamt-pagecache-base9 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 tls-maxphys-base matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base
# 1.58 04-Jan-2012 christos

branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 03-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.55 06-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


Revision tags: matt-mips64-premerge-20101231
# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


Revision tags: matt-premerge-20091211
# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE jym-xensuspend-nbase netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 jym-xensuspend-base netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.51 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 wrstuden-revivesa-base
# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.48 26-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


Revision tags: abandoned-netbsd-4-base
# 1.44 16-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 15-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 17-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 24-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-3-base netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


Revision tags: fvdl_fs64_base
# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 07-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 03-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


Revision tags: netbsd-1-5-base minoura-xpg4dl-base wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.28 05-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 25-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 19-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 28-Jul-1998 mycroft

Delint.


# 1.21 28-Jul-1998 mycroft

Delint.


# 1.20 28-Jul-1998 mycroft

Delint.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 20-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 19-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 09-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 02-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 26-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.9 28-Mar-1994 cgd

no more MAP_FILE


# 1.8 25-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 07-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.60 16-May-2020 christos

Add ACL support for FFS. From FreeBSD.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.59 05-Mar-2016 uwe

branches: 1.59.16;
The '-i' flag should work regardless of whether the standard input is
a terminal. The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense. Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-7-base yamt-pagecache-base9 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 tls-maxphys-base matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base
# 1.58 04-Jan-2012 christos

branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 03-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.55 06-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


Revision tags: matt-mips64-premerge-20101231
# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


Revision tags: matt-premerge-20091211
# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE jym-xensuspend-nbase netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 jym-xensuspend-base netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.51 20-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 wrstuden-revivesa-base
# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.48 26-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


Revision tags: abandoned-netbsd-4-base
# 1.44 16-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 15-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 17-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 24-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-3-base netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


Revision tags: fvdl_fs64_base
# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 07-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 03-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


Revision tags: netbsd-1-5-base minoura-xpg4dl-base wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.28 05-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 25-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 19-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 28-Jul-1998 mycroft

Delint.


# 1.21 28-Jul-1998 mycroft

Delint.


# 1.20 28-Jul-1998 mycroft

Delint.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 20-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 19-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 09-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 02-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 26-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.9 28-Mar-1994 cgd

no more MAP_FILE


# 1.8 25-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 07-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base netbsd-0-8 netbsd-alpha-1
# 1.3 23-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.59 05-Mar-2016 uwe

The '-i' flag should work regardless of whether the standard input is
a terminal. The Open Group notes this historic behavior and correctly
notes that it doesn't make much sense. Note also, that mv(1) has
always respected its '-i' regardless of whether the standard input is
a terminal.

From Timo Buhrmester.


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-7-base yamt-pagecache-base9 netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 agc-symver-base netbsd-6-1-RC2 netbsd-6-1-RC1 yamt-pagecache-base8 netbsd-6-0-1-RELEASE yamt-pagecache-base7 matt-nb6-plus-nbase yamt-pagecache-base6 netbsd-6-0-RELEASE netbsd-6-0-RC2 tls-maxphys-base matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base
# 1.58 04-Jan-2012 christos

branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 02-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.55 05-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


Revision tags: matt-mips64-premerge-20101231
# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


Revision tags: matt-premerge-20091211
# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE jym-xensuspend-nbase netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 jym-xensuspend-base netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.51 19-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 wrstuden-revivesa-base
# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-pf42-base keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking cube-autoconf-base matt-armv6-base matt-mips64-base hpcarm-cleanup-base
# 1.48 25-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 wrstuden-fixsa-base netbsd-4-base
# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


Revision tags: abandoned-netbsd-4-base
# 1.44 16-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 14-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 16-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 23-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-3-base netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


Revision tags: fvdl_fs64_base
# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 06-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 02-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


Revision tags: netbsd-1-5-base minoura-xpg4dl-base wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 1.28 05-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 24-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 18-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 27-Jul-1998 mycroft

Delint.


# 1.21 27-Jul-1998 mycroft

Delint.


# 1.20 27-Jul-1998 mycroft

Delint.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 19-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 18-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 08-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


Revision tags: netbsd-1-2-PATCH001 netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 01-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 25-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.9 27-Mar-1994 cgd

no more MAP_FILE


# 1.8 24-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 06-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base netbsd-0-8 netbsd-alpha-1
# 1.3 22-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.58 04-Jan-2012 christos

Add siginfo support from Daniel Loffgren.


# 1.57 18-Aug-2011 manu

branches: 1.57.2;
Remove warning about system extended attributes that cannot be copied, since
it will always be displayed when an unprivilegied user moves files across
filesystems (mv(1) uses cp -p in that case). After all, there is no warning
that we loose a setuid bit during a move or copy, so this makes sense.

Fixes bin/45259


# 1.56 02-Aug-2011 manu

Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.


# 1.55 06-Feb-2011 darcy

Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.


# 1.54 21-Dec-2010 christos

branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov


# 1.53 08-Oct-2009 pooka

Fix the "dne" handling and chmod behaviour properly: values of dne
need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.

This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.

all regression tests passed


# 1.52 29-Sep-2009 pooka

Remove fts sorting. It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.


# 1.51 19-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.


# 1.50 26-May-2008 dholland

Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)


# 1.49 26-May-2008 christos

PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale


# 1.48 25-Dec-2006 alc

branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)


# 1.47 15-Oct-2006 christos

c99 initializers


# 1.46 15-Aug-2006 jschauma

initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.


# 1.45 15-Aug-2006 tron

Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.


# 1.44 15-Jul-2006 jschauma

branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.


# 1.43 15-Jul-2006 jschauma

The last commit introduced a bug. Revert until that's found and fixed.


# 1.42 14-Jul-2006 jschauma

As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).


# 1.41 16-Mar-2006 erh

Fix Coverity issue 1754. Call fts_close() after we're done copying.


# 1.40 16-Nov-2005 christos

- Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo


# 1.39 24-Oct-2005 kleink

Remove the "" -> "." target conversion kludge.


# 1.38 15-Oct-2005 christos

- Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.


# 1.37 15-Aug-2005 elad

Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.


# 1.36 26-Jun-2005 christos

sprinkle a little const, and now everything compiles with WARNS=3


# 1.35 14-Sep-2003 jschauma

Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''


# 1.34 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.


# 1.33 04-Aug-2003 jschauma

As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.


# 1.32 16-Dec-2002 jrf

Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.


# 1.31 13-Sep-2001 wiz

ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.


# 1.30 07-Jul-2000 itojun

errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd


# 1.29 02-Jul-2000 matt

include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96


# 1.28 04-Sep-1999 kleink

branches: 1.28.8;
Initialize locale on startup.


# 1.27 01-Mar-1999 mjl

Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.


# 1.26 24-Feb-1999 dean

Got rid of redundant error message (X is a directory (not copied). was
printed twice)


# 1.25 08-Oct-1998 wsanchez

Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.


# 1.24 18-Aug-1998 thorpej

Add some braces to keep egcs happy.


# 1.23 28-Jul-1998 mycroft

Be more retentive about use of NOTREACHED and noreturn.


# 1.22 27-Jul-1998 mycroft

Delint.


# 1.21 27-Jul-1998 mycroft

Delint.


# 1.20 27-Jul-1998 mycroft

Delint.


# 1.19 14-Sep-1997 lukem

* getopt returns -1 not EOF
* cleanup use of .Nm in manpage


# 1.18 19-Jul-1997 thorpej

- Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.


# 1.17 21-May-1997 kleink

Fix one remaining botch when copying directory trees using -R.


# 1.16 18-May-1997 kleink

Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.


# 1.15 09-Apr-1997 kleink

Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.


# 1.14 07-Sep-1995 jtc

Sync with 4.4lite2


# 1.13 01-Apr-1995 mycroft

Fix typo in S_FIFO case when copying recursively.


# 1.12 21-Mar-1995 cgd

convert to new RCS id conventions.


# 1.11 25-Jan-1995 mycroft

Fix core dump reported by Wolfram Schneider.


# 1.10 22-Sep-1994 mycroft

Merge 4.4-Lite version.


# 1.9 27-Mar-1994 cgd

no more MAP_FILE


# 1.8 24-Feb-1994 jtc

POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.


# 1.7 09-Nov-1993 jtc

Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.


# 1.6 30-Oct-1993 mycroft

From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.


# 1.5 06-Aug-1993 mycroft

New version from uunet. Uses mmap().


# 1.4 01-Aug-1993 mycroft

Add RCS identifiers.


# 1.3 22-Mar-1993 cgd

changed "Id" to "Header" for rcsids


# 1.2 22-Mar-1993 cgd

added rcs ids to all files


# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
Initial revision


# 1.1.1.3 07-Sep-1995 jtc

imported from 44lite2


# 1.1.1.2 21-Sep-1994 mycroft

Import original 4.4-Lite version.


# 1.1.1.1 21-Mar-1993 cgd

initial import of 386bsd-0.1 sources


# 1.28.8.1 26-Jul-2000 itojun

pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/bin/dd/conv.c 1.8 -> 1.9
/cvsroot/basesrc/bin/cp/cp.c 1.29 -> 1.30
/cvsroot/basesrc/bin/chmod/chmod.c 1.22 -> 1.23


# 1.44.2.1 21-Aug-2006 ghen

Pull up following revision(s) (requested by tron in ticket #30):
regress/bin/cp/cp.sh: revision 1.2
regress/bin/cp/cp.sh: revision 1.3
bin/cp/cp.c: revision 1.45
bin/cp/cp.c: revision 1.46
Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.
initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.
allow each dir_to_dir test to be run individually without having to
rely on previous tests that set up the files and directories;
while here, clarify in each error message where exactly the error occurred
add a regression test for copying several subdirs into a target directory
where some subdirs already exist


# 1.48.12.2 17-Sep-2008 wrstuden

Sync with wrstuden-revivesa-base-2.


# 1.48.12.1 22-Jun-2008 wrstuden

Sync w/ -current. 34 merge conflicts to follow.


# 1.48.10.1 03-Jun-2008 yamt

sync with head


# 1.54.2.1 08-Feb-2011 bouyer

Sync with HEAD


# 1.57.2.1 16-Apr-2012 yamt

sync with head