diff options
author | bdrewery <bdrewery@FreeBSD.org> | 2015-06-07 06:30:25 +0000 |
---|---|---|
committer | bdrewery <bdrewery@FreeBSD.org> | 2015-06-07 06:30:25 +0000 |
commit | 4e68976c74c31df589e6df98a36af08d01812eb3 (patch) | |
tree | f14fc15dd11f8aa22eae8093c31c9482a73ff4e6 /bin/cp/cp.c | |
parent | 939189542ecd10392ffaf53f33e9ea26735a3b84 (diff) | |
download | FreeBSD-src-4e68976c74c31df589e6df98a36af08d01812eb3.zip FreeBSD-src-4e68976c74c31df589e6df98a36af08d01812eb3.tar.gz |
Implement '-s' to copy as symlink, similar to the current -l link(2) handling.
This is also implemented in at least GNU coreutils cp.
While here also improve the '-l' handling to not open(2) the source file as
it does not actually need the descriptor.
Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'bin/cp/cp.c')
-rw-r--r-- | bin/cp/cp.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 2ad5f4a..18eb52e 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -83,7 +83,7 @@ static char emptystring[] = ""; PATH_T to = { to.p_path, emptystring, "" }; -int fflag, iflag, lflag, nflag, pflag, vflag; +int fflag, iflag, lflag, nflag, pflag, sflag, vflag; static int Rflag, rflag; volatile sig_atomic_t info; @@ -102,7 +102,7 @@ main(int argc, char *argv[]) fts_options = FTS_NOCHDIR | FTS_PHYSICAL; Hflag = Lflag = 0; - while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1) + while ((ch = getopt(argc, argv, "HLPRafilnprsvx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -145,6 +145,9 @@ main(int argc, char *argv[]) rflag = Lflag = 1; Hflag = 0; break; + case 's': + sflag = 1; + break; case 'v': vflag = 1; break; @@ -163,6 +166,8 @@ main(int argc, char *argv[]) if (Rflag && rflag) errx(1, "the -R and -r options may not be specified together"); + if (lflag && sflag) + errx(1, "the -l and -s options may not be specified together"); if (rflag) Rflag = 1; if (Rflag) { @@ -452,7 +457,7 @@ copy(char *argv[], enum op type, int fts_options) break; case S_IFBLK: case S_IFCHR: - if (Rflag) { + if (Rflag && !sflag) { if (copy_special(curr->fts_statp, !dne)) badcp = rval = 1; } else { @@ -465,7 +470,7 @@ copy(char *argv[], enum op type, int fts_options) curr->fts_path); break; case S_IFIFO: - if (Rflag) { + if (Rflag && !sflag) { if (copy_fifo(curr->fts_statp, !dne)) badcp = rval = 1; } else { |