History log of /openbsd-current/bin/cp/utils.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.50 28-Nov-2021 deraadt

Stop using MAXBSIZE to eliminate sys/param.h including (which injects a
ton of namespace intrusion). Create local sizes, and refactor some code
along the way.
ok millert


# 1.49 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.48 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.47 28-Jan-2019 jca

Implement cp -a ("archive" mode)

Not standard, but supported at least by GNU cp, IllumOS, NetBSD,
FreeBSD, DragonflyBSD. No need to be gratuitously different. This
should also allow us to drop patches in ~10 ports.

Based on an initial diff by benno@ with input from sthen@ and jmc@
ok benno@ danj@ sthen@ martijn@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.46 07-Sep-2018 martijn

Revert earlier revert.
It turned out the issue was a badly applied diff on stsp@'s machine.

OK stsp@


# 1.45 07-Sep-2018 stsp

Backout recent cp(1) changes; they broke texlive's mktexlsr(1)


# 1.44 07-Sep-2018 martijn

Rename dne in copy_file to exists to be more consistent with the other
copy_* functions.

OK stsp@


# 1.43 07-Sep-2018 martijn

Also verify a overwrite for the copy of a fifo, link and device node.

OK stsp@


# 1.42 07-Sep-2018 martijn

Move the question to allow a copy to its own function.

OK stsp@


# 1.41 07-Sep-2018 martijn

The combination of -v and -i and the deny of a copy would cause the copy
still to be printed. This fixes that edge-case.

OK stsp@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.49 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.48 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.47 28-Jan-2019 jca

Implement cp -a ("archive" mode)

Not standard, but supported at least by GNU cp, IllumOS, NetBSD,
FreeBSD, DragonflyBSD. No need to be gratuitously different. This
should also allow us to drop patches in ~10 ports.

Based on an initial diff by benno@ with input from sthen@ and jmc@
ok benno@ danj@ sthen@ martijn@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.46 07-Sep-2018 martijn

Revert earlier revert.
It turned out the issue was a badly applied diff on stsp@'s machine.

OK stsp@


# 1.45 07-Sep-2018 stsp

Backout recent cp(1) changes; they broke texlive's mktexlsr(1)


# 1.44 07-Sep-2018 martijn

Rename dne in copy_file to exists to be more consistent with the other
copy_* functions.

OK stsp@


# 1.43 07-Sep-2018 martijn

Also verify a overwrite for the copy of a fifo, link and device node.

OK stsp@


# 1.42 07-Sep-2018 martijn

Move the question to allow a copy to its own function.

OK stsp@


# 1.41 07-Sep-2018 martijn

The combination of -v and -i and the deny of a copy would cause the copy
still to be printed. This fixes that edge-case.

OK stsp@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.48 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.47 28-Jan-2019 jca

Implement cp -a ("archive" mode)

Not standard, but supported at least by GNU cp, IllumOS, NetBSD,
FreeBSD, DragonflyBSD. No need to be gratuitously different. This
should also allow us to drop patches in ~10 ports.

Based on an initial diff by benno@ with input from sthen@ and jmc@
ok benno@ danj@ sthen@ martijn@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.46 07-Sep-2018 martijn

Revert earlier revert.
It turned out the issue was a badly applied diff on stsp@'s machine.

OK stsp@


# 1.45 07-Sep-2018 stsp

Backout recent cp(1) changes; they broke texlive's mktexlsr(1)


# 1.44 07-Sep-2018 martijn

Rename dne in copy_file to exists to be more consistent with the other
copy_* functions.

OK stsp@


# 1.43 07-Sep-2018 martijn

Also verify a overwrite for the copy of a fifo, link and device node.

OK stsp@


# 1.42 07-Sep-2018 martijn

Move the question to allow a copy to its own function.

OK stsp@


# 1.41 07-Sep-2018 martijn

The combination of -v and -i and the deny of a copy would cause the copy
still to be printed. This fixes that edge-case.

OK stsp@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.47 28-Jan-2019 jca

Implement cp -a ("archive" mode)

Not standard, but supported at least by GNU cp, IllumOS, NetBSD,
FreeBSD, DragonflyBSD. No need to be gratuitously different. This
should also allow us to drop patches in ~10 ports.

Based on an initial diff by benno@ with input from sthen@ and jmc@
ok benno@ danj@ sthen@ martijn@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.46 07-Sep-2018 martijn

Revert earlier revert.
It turned out the issue was a badly applied diff on stsp@'s machine.

OK stsp@


# 1.45 07-Sep-2018 stsp

Backout recent cp(1) changes; they broke texlive's mktexlsr(1)


# 1.44 07-Sep-2018 martijn

Rename dne in copy_file to exists to be more consistent with the other
copy_* functions.

OK stsp@


# 1.43 07-Sep-2018 martijn

Also verify a overwrite for the copy of a fifo, link and device node.

OK stsp@


# 1.42 07-Sep-2018 martijn

Move the question to allow a copy to its own function.

OK stsp@


# 1.41 07-Sep-2018 martijn

The combination of -v and -i and the deny of a copy would cause the copy
still to be printed. This fixes that edge-case.

OK stsp@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.46 07-Sep-2018 martijn

Revert earlier revert.
It turned out the issue was a badly applied diff on stsp@'s machine.

OK stsp@


# 1.45 07-Sep-2018 stsp

Backout recent cp(1) changes; they broke texlive's mktexlsr(1)


# 1.44 07-Sep-2018 martijn

Rename dne in copy_file to exists to be more consistent with the other
copy_* functions.

OK stsp@


# 1.43 07-Sep-2018 martijn

Also verify a overwrite for the copy of a fifo, link and device node.

OK stsp@


# 1.42 07-Sep-2018 martijn

Move the question to allow a copy to its own function.

OK stsp@


# 1.41 07-Sep-2018 martijn

The combination of -v and -i and the deny of a copy would cause the copy
still to be printed. This fixes that edge-case.

OK stsp@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_2_BASE
# 1.40 27-Jun-2017 tedu

add a -v verbose flag to cp, mv, and rm. useful for monitoring progress,
and present on several other systems. some ok, some less ok.
from Job Snijders


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.39 26-Dec-2015 guenther

Set the times, mode, and flags on symlinks when doing cp -p (or mv across
filesystems)

problem noted by Carsten Kunze (carsten.kunze (at) arcor.de)


# 1.38 16-Nov-2015 tedu

rename link to name to avoid shadowing the function


Revision tags: OPENBSD_5_8_BASE
# 1.37 03-May-2015 guenther

Preserve times to nanosecond precision instead of just microsecond.
Prefer to set attributes by fd for regular files, and not follwing
symlinks for others.

ok brynet@ millert@


Revision tags: OPENBSD_5_7_BASE
# 1.36 19-Jan-2015 deraadt

cleanup sys/param.h comment


# 1.35 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


Revision tags: OPENBSD_5_6_BASE
# 1.34 24-Apr-2014 tedu

calloc is better. from Peter Malone


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.33 11-Jul-2012 matthew

When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original
file's length was. This fixes things like "cp /dev/ksyms /tmp" so
that we don't truncate the file to 0 bytes after copying all of the
data.

ok tedu, millert


# 1.32 11-Apr-2012 espie

if we ever activate that, this may need fixing


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.31 23-Jun-2011 otto

set set*id bits only if the target did not exist and -p was not used;
from netbsd, prompted by Jesus Sanchez. ok miller@


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.30 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.29 22-Sep-2007 sobrado

warn should return an error message for chmod, not for chown

ok millert@


# 1.28 16-Sep-2007 sobrado

"source" and "target" can be either files or directories;
cp(1) and ln(1) must have a synopsis consistent with mkdir(1),
mv(1), rmdir(1) and others

ok jmc@, millert@, otto@


Revision tags: OPENBSD_4_2_BASE
# 1.27 06-Apr-2007 tedu

when copying regular files, look for blocks of zeroes. when we see them,
just lseek ahead to create a sparse file. saves disk and time.
note this behavior in the man page.
ok? deraadt millert


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.26 10-Dec-2004 jmc

sort options + sync usage();
standard EXAMPLES;
various other tweaks;

ok millert@


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.25 24-Nov-2003 mickey

madvise mmapped memory (not used code)


Revision tags: OPENBSD_3_4_BASE
# 1.24 06-Aug-2003 millert

Remove some double semicolons (hmm, do two semis equal a maxi?).
I've skipped the GNU stuff for now. From Patrick Latifi.


# 1.23 29-Jul-2003 deraadt

spacing


# 1.22 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.21 01-Jun-2003 millert

Undo a misguided attempt to fix speling errors from long ago. UCB
copyrights say "acknowledgement", not "acknowledgment". You cannot
just go changing the text of a license willy-nilly.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.20 04-Jul-2002 deraadt

ansi


# 1.19 30-May-2002 deraadt

typo; moritz@jodeit.org


Revision tags: OPENBSD_3_1_BASE
# 1.18 05-Nov-2001 mpech

kill more registers;

millert@ ok


Revision tags: OPENBSD_3_0_BASE
# 1.17 06-Sep-2001 mpech

o) __progname aria;

millert@ ok.


# 1.16 25-Jun-2001 art

explicit braces to avoid ambiguous else


# 1.15 11-May-2001 art

Explicit mapping type to mmap. (not used yet)


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.14 06-May-1999 millert

"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.13 26-Sep-1998 deraadt

for -p preserve sticky bit


# 1.12 07-Jun-1998 deraadt

use MAP_FAILED


# 1.11 18-May-1998 deraadt

readlink(path, buf, sizeof buf-1). Never forget that -1.


Revision tags: OPENBSD_2_3_BASE
# 1.10 08-Nov-1997 todd

spelling


Revision tags: OPENBSD_2_2_BASE
# 1.9 01-Sep-1997 deraadt

i am bored enough to fix terminal space/tab uglies


# 1.8 31-Jul-1997 kstailey

improve error message (yes I know mmap(2) isn't used yet.)


# 1.7 28-May-1997 deraadt

bad usage line; oster@cs.usask.ca


Revision tags: OPENBSD_2_1_BASE
# 1.6 05-Apr-1997 tholo

Patch from BSDI (via Keith Bostic, via NetBSD):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)


# 1.5 25-Feb-1997 millert

Better fix for -p and links.


# 1.4 24-Feb-1997 millert

Only update owner (via lchown) when dealing with symbolic links.
Fixes core dump problem with ``-p'' and symbolic links. Noted by
Carsten Hammer <chammer@post.uni-bielefeld.de>.


# 1.3 26-Jan-1997 kstailey

support for lchown(2) if "-p" is used


Revision tags: OPENBSD_2_0_BASE
# 1.2 23-Jun-1996 deraadt

update rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision