to be verbose, showing files as they are copied.
.It Fl X
Do not copy Extended Attributes (EAs) or resource forks.
+.It Fl c
+copy files using clonefile(2)
.El
.Pp
For each destination file that already exists, its contents are
int Xflag;
#endif /* __APPLE__ */
static int Rflag, rflag;
+ int cflag = 0;
volatile sig_atomic_t info;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
char *target;
Hflag = Lflag = Pflag = 0;
- while ((ch = getopt(argc, argv, "HLPRXafinprv")) != -1)
+ while ((ch = getopt(argc, argv, "cHLPRXafinprv")) != -1)
switch (ch) {
+ case 'c':
+ cflag = 1;
+ break;
case 'H':
Hflag = 1;
Lflag = Pflag = 0;
if (argc < 2)
usage();
+ if (cflag && Xflag) {
+ errx(1, "the -c and -X options may not be specified together");
+ }
+
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
if (rflag) {
if (Rflag)
#ifdef __APPLE__
extern int Xflag;
#endif /* __APPLE__ */
+extern int cflag;
extern volatile sig_atomic_t info;
__BEGIN_DECLS
#include <string.h>
#include <sys/mount.h>
#include <get_compat.h>
+#include <sys/attr.h>
+#include <sys/clonefile.h>
#else
#define COMPAT_MODE(a,b) (1)
#endif /* __APPLE__ */
}
}
+ if (cflag) {
+ (void)unlink(to.p_path);
+ int error = clonefile(entp->fts_path, to.p_path, 0);
+ if (error)
+ warn("%s: clonefile failed", to.p_path);
+ (void)close(from_fd);
+ return error == 0 ? 0 : 1;
+ }
+
if (COMPAT_MODE("bin/cp", "unix2003")) {
/* first try to overwrite existing destination file name */
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
/* overwrite existing destination file name */
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
}
- } else
+ } else {
+
+ if (cflag) {
+ int error = clonefile(entp->fts_path, to.p_path, 0);
+ if (error)
+ warn("%s: clonefile failed", to.p_path);
+ (void)close(from_fd);
+ return error == 0 ? 0 : 1;
+ }
+
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
fs->st_mode & ~(S_ISUID | S_ISGID));
+ }
if (to_fd == -1) {
warn("%s", to.p_path);
if (COMPAT_MODE("bin/cp", "unix2003")) {
(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file",
-" cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file",
+" cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... "
"target_directory");
} else {
(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-apvX] source_file target_file",
-" cp [-R [-H | -L | -P]] [-f | -i | -n] [-apvX] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-apvXc] source_file target_file",
+" cp [-R [-H | -L | -P]] [-f | -i | -n] [-apvXc] source_file ... "
"target_directory");
}
exit(EX_USAGE);
set -x
case "$PLATFORM_NAME" in
-iphoneos|appletvos|watchos)
+iphoneos|appletvos|watchos|bridgeos)
ln -hfs /usr/local/bin/dd "$DSTROOT"/bin/dd
;;
macosx)
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
+ 3E59B9311D4A767600D3128C /* futimens.c in Sources */ = {isa = PBXBuildFile; fileRef = 3E59B9301D4A767600D3128C /* futimens.c */; };
FC8A8A2814B6486E001B97AD /* chflags.c in Sources */ = {isa = PBXBuildFile; fileRef = FCB1BDCC14B6460C0070FACB /* chflags.c */; };
FC8A8BE414B6494B001B97AD /* chflags.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = FCB1BDCB14B6460C0070FACB /* chflags.1 */; };
FC8A8BE514B64958001B97AD /* chmod.c in Sources */ = {isa = PBXBuildFile; fileRef = FCB1BDD014B6460C0070FACB /* chmod.c */; };
/* Begin PBXFileReference section */
0773099A1A3A4DFE00E9B4EA /* dd.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = dd.entitlements; sourceTree = "<group>"; };
+ 3E59B9301D4A767600D3128C /* futimens.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = futimens.c; sourceTree = "<group>"; };
FC8A8B1214B648D7001B97AD /* chmod */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = chmod; sourceTree = BUILT_PRODUCTS_DIR; };
FC8A8B1A14B648E0001B97AD /* chown */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = chown; sourceTree = BUILT_PRODUCTS_DIR; };
FC8A8B2214B648E3001B97AD /* cksum */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cksum; sourceTree = BUILT_PRODUCTS_DIR; };
FDAD947F1808BB3A00B4D5A0 /* gzip */ = {
isa = PBXGroup;
children = (
+ 3E59B9301D4A767600D3128C /* futimens.c */,
FDAD94801808BB3A00B4D5A0 /* gzexe */,
FDAD94811808BB3A00B4D5A0 /* gzexe.1 */,
FDAD94821808BB3A00B4D5A0 /* gzip.1 */,
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 3E59B9311D4A767600D3128C /* futimens.c in Sources */,
FDAD949F1808BBB900B4D5A0 /* gzip.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
--- /dev/null
+/*-
+ * Copyright (c) 2015 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/time.h>
+
+#ifndef UTIME_NOW
+#define UTIME_NOW -1
+#endif
+
+#ifndef UTIME_OMIT
+#define UTIME_OMIT -2
+#endif
+int futimens(int fd, const struct timespec times[2]);
+
+int
+futimens(int fd, const struct timespec times[2])
+{
+ struct timeval now, tv[2], *tvp;
+ struct stat sb;
+
+ if (times == NULL || (times[0].tv_nsec == UTIME_NOW &&
+ times[1].tv_nsec == UTIME_NOW))
+ tvp = NULL;
+ else if (times[0].tv_nsec == UTIME_OMIT &&
+ times[1].tv_nsec == UTIME_OMIT)
+ return (0);
+ else {
+ if ((times[0].tv_nsec < 0 || times[0].tv_nsec > 999999999) &&
+ times[0].tv_nsec != UTIME_NOW &&
+ times[0].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if ((times[1].tv_nsec < 0 || times[1].tv_nsec > 999999999) &&
+ times[1].tv_nsec != UTIME_NOW &&
+ times[1].tv_nsec != UTIME_OMIT) {
+ errno = EINVAL;
+ return (-1);
+ }
+ tv[0].tv_sec = times[0].tv_sec;
+ tv[0].tv_usec = times[0].tv_nsec / 1000;
+ tv[1].tv_sec = times[1].tv_sec;
+ tv[1].tv_usec = times[1].tv_nsec / 1000;
+ tvp = tv;
+ if (times[0].tv_nsec == UTIME_OMIT ||
+ times[1].tv_nsec == UTIME_OMIT) {
+ if (fstat(fd, &sb) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_OMIT) {
+ tv[0].tv_sec = sb.st_atimespec.tv_sec;
+ tv[0].tv_usec = sb.st_atimespec.tv_nsec / 1000;
+ }
+ if (times[1].tv_nsec == UTIME_OMIT) {
+ tv[1].tv_sec = sb.st_mtimespec.tv_sec;
+ tv[1].tv_usec = sb.st_mtimespec.tv_nsec / 1000;
+ }
+ }
+ if (times[0].tv_nsec == UTIME_NOW ||
+ times[1].tv_nsec == UTIME_NOW) {
+ if (gettimeofday(&now, NULL) == -1)
+ return (-1);
+ if (times[0].tv_nsec == UTIME_NOW)
+ tv[0] = now;
+ if (times[1].tv_nsec == UTIME_NOW)
+ tv[1] = now;
+ }
+ }
+ return (futimes(fd, tvp));
+}
-.\" $NetBSD: gzip.1,v 1.21 2011/06/19 02:22:36 christos Exp $
+.\" $NetBSD: gzip.1,v 1.26 2015/10/27 07:36:18 mrg Exp $
.\"
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
.\" All rights reserved.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/usr.bin/gzip/gzip.1,v 1.11 2011/10/10 06:37:32 delphij Exp $
-.Dd October 9, 2011
+.\" $FreeBSD: head/usr.bin/gzip/gzip.1 290073 2015-10-27 21:26:05Z delphij $
+.Dd October 26, 2015
.Dt GZIP 1
.Os
.Sh NAME
and
.Fl d
options are enabled.
-When invoked as
-.Nm zcat ,
-.Dq .Z
-will be appended to all filenames that do not have that suffix.
.Pp
This version of
.Nm
is also capable of decompressing files compressed using
-.Xr compress 1
+.Xr compress 1 ,
+.Xr bzip2 1 ,
or
-.Xr bzip2 1 .
+.Xr xz 1 .
.Sh OPTIONS
The following options are available:
.Bl -tag -width XXrXXXrecursiveX
.It Fl h , -help
This option prints a usage summary and exits.
.It Fl k , -keep
-Keep (don't delete) input files during compression
+Keep (do not delete) input files during compression
or decompression.
.It Fl L , -license
This option prints
handled before any options on the command line.
Options on the command line will override anything in
.Ev GZIP .
+.Sh EXIT STATUS
+The
+.Nm
+utility exits 0 on success,
+1 on errors,
+and 2 if a warning occurs.
.Sh SEE ALSO
.Xr bzip2 1 ,
.Xr compress 1 ,
.Xr xz 1 ,
.Xr fts 3 ,
-.Xr zlib 3 ,
-.Xr compat 5
+.Xr zlib 3
.Sh HISTORY
The
.Nm
This implementation of
.Nm
was written by
-.An Matthew R. Green Aq mrg@eterna.com.au
+.An Matthew R. Green Aq Mt mrg@eterna.com.au
with unpack support written by
-.An Xin LI Aq delphij@FreeBSD.org .
+.An Xin LI Aq Mt delphij@FreeBSD.org .
.Sh BUGS
According to RFC 1952, the recorded file size is stored in a 32-bit
-integer, therefore, it can not represent files larger than 4GB.
+integer, therefore, it cannot represent files larger than 4GB.
This limitation also applies to
.Fl l
option of
-/* $NetBSD: gzip.c,v 1.105 2011/08/30 23:06:00 joerg Exp $ */
+/* $NetBSD: gzip.c,v 1.109 2015/10/27 07:36:18 mrg Exp $ */
/*-
* Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
Matthew R. Green. All rights reserved.");
-__FBSDID("$FreeBSD: src/usr.bin/gzip/gzip.c,v 1.25 2011/10/10 06:37:32 delphij Exp $");
+__FBSDID("$FreeBSD: head/usr.bin/gzip/gzip.c 290073 2015-10-27 21:26:05Z delphij $");
#endif /* not lint */
/*
#include <sys/attr.h>
#include <copyfile.h>
#include <get_compat.h>
+int futimens(int fd, const struct timespec times[2]);
#endif /* __APPLE__ */
/* what type of file are we dealing with */
#ifdef __APPLE__
static const char gzip_version[] = "Apple gzip " GZIP_APPLE_VERSION;
#else
-static const char gzip_version[] = "FreeBSD gzip 20111009";
+static const char gzip_version[] = "FreeBSD gzip 20150413";
#endif
#ifndef SMALL
if (in_tot > 0) {
maybe_warnx("%s: trailing garbage "
"ignored", filename);
+ exit_value = 2;
goto stop;
}
maybe_warnx("input not gziped (MAGIC0)");
static void
copymodes(int fd, const struct stat *sbp, const char *file)
{
- struct timeval times[2];
+ struct timespec times[2];
struct stat sb;
/*
maybe_warn("couldn't fchmod: %s", file);
#ifdef __APPLE__
- TIMESPEC_TO_TIMEVAL(×[0], &sb.st_atimespec);
- TIMESPEC_TO_TIMEVAL(×[1], &sb.st_mtimespec);
+ times[0] = sb.st_atimespec;
+ times[1] = sb.st_mtimespec;
#else
- TIMESPEC_TO_TIMEVAL(×[0], &sb.st_atim);
- TIMESPEC_TO_TIMEVAL(×[1], &sb.st_mtim);
+ times[0] = sb.st_atim;
+ times[1] = sb.st_mtim;
#endif
- if (futimes(fd, times) < 0)
- maybe_warn("couldn't utimes: %s", file);
+ if (futimens(fd, times) < 0)
+ maybe_warn("couldn't futimens: %s", file);
/* only try flags if they exist already */
if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
#ifndef SMALL
ssize_t rv;
time_t timestamp = 0;
- unsigned char name[PATH_MAX + 1];
+ char name[PATH_MAX + 1];
#endif
/* gather the old name info */
timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
if (header1[3] & ORIG_NAME) {
- rbytes = pread(fd, name, sizeof name, GZIP_ORIGNAME);
+ rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME);
if (rbytes < 0) {
maybe_warn("can't read %s", file);
goto lose;
}
- if (name[0] != 0) {
+ if (name[0] != '\0') {
+ char *dp, *nf;
+
+ /* Make sure that name is NUL-terminated */
+ name[rbytes] = '\0';
+
+ /* strip saved directory name */
+ nf = strrchr(name, '/');
+ if (nf == NULL)
+ nf = name;
+ else
+ nf++;
+
/* preserve original directory name */
- char *dp = strrchr(file, '/');
+ dp = strrchr(file, '/');
if (dp == NULL)
dp = file;
else
dp++;
snprintf(outfile, outsize, "%.*s%.*s",
(int) (dp - file),
- file, (int) rbytes, name);
+ file, (int) rbytes, nf);
}
}
}
return;
}
#endif
- /* If stdin is a file use it's mtime, otherwise use current time */
+ /* If stdin is a file use its mtime, otherwise use current time */
ret = fstat(STDIN_FILENO, &sb);
#ifndef SMALL
{
#ifdef __APPLE__
- fprintf(stderr, "%s (based on FreeBSD gzip 20111009)\n", gzip_version);
+ fprintf(stderr, "%s (based on FreeBSD gzip 20150113)\n", gzip_version);
#else
- fprintf(stderr, "%s (based on NetBSD gzip 20111009)\n", gzip_version);
+ fprintf(stderr, "%s (based on NetBSD gzip 20150113)\n", gzip_version);
#endif
fprintf(stderr, "%s\n", gzip_copyright);
exit(0);
#!/bin/sh -
#
-# $NetBSD: zmore,v 1.3 2004/03/29 09:59:42 wiz Exp $
-# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $
+# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
+#
+# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
#
#-
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
# Agency (DARPA) and Air Force Research Laboratory, Air Force
# Materiel Command, USAF, under agreement number F39502-99-1-0512.
#
-# $FreeBSD: src/usr.bin/gzip/zmore,v 1.1 2007/01/26 10:19:07 delphij Exp $
-
-if [ "$0" = "zless" ]; then
-zpager="less"
-else
-zpager="more"
-fi
+# $FreeBSD: head/usr.bin/gzip/zmore 273507 2014-10-23 01:22:29Z delphij $
# Pull out any command line flags so we can pass them to more/less
flags=
esac
done
+if [ `basename $0` = "zless" ] ; then
+ pager=${PAGER-less}
+else
+ pager=${PAGER-more}
+fi
+
# No files means read from stdin
if [ $# -eq 0 ]; then
- gzip -cdfq 2>&1 | ${PAGER-${zpager}} $flags
+ gzip -cdfq 2>&1 | $pager $flags
exit 0
fi
oterm=`stty -g 2>/dev/null`
while test $# -ne 0; do
- gzip -cdfq "$1" 2>&1 | ${PAGER-${zpager}} $flags
+ gzip -cdfq "$1" 2>&1 | $pager $flags
prev="$1"
shift
if tty -s && test -n "$oterm" -a $# -gt 0; then
-.\" $NetBSD: zmore.1,v 1.3 2003/12/28 12:47:52 wiz Exp $
-.\" $OpenBSD: zmore.1,v 1.3 2003/06/23 21:00:48 deraadt Exp $
+.\" $NetBSD: zmore.1,v 1.4 2013/11/12 21:58:37 pettai Exp $
+.\" $OpenBSD: zmore.1,v 1.10 2009/08/16 09:41:08 sobrado Exp $
.\"
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
.\"
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
-.\" $FreeBSD: src/usr.bin/gzip/zmore.1,v 1.3 2012/06/05 03:14:39 eadler Exp $
-.Dd February 6, 2011
+.\" $FreeBSD: head/usr.bin/gzip/zmore.1 273507 2014-10-23 01:22:29Z delphij $
+.Dd October 22, 2014
.Dt ZMORE 1
.Os
.Sh NAME
-.Nm zmore
+.Nm zmore ,
+.Nm zless
.Nd view compressed files
.Sh SYNOPSIS
.Nm zmore
.Op Ar flags
-.Op Ar file ...
+.Op Ar
+.Nm zless
+.Op Ar flags
+.Op Ar
.Sh DESCRIPTION
.Nm
is a filter that allows the viewing of files compressed with Lempel-Ziv
.Pa /usr/bin/more
by default).
.Pp
+.Nm zless
+is equivalent to
+.Nm zmore
+but uses
+.Xr less 1
+as a pager instead of
+.Xr more 1 .
+.Pp
When multiple files are specified,
.Nm
will pause at the end of each file and present the following prompt to the user:
Program used to display files.
If unset,
.Pa /usr/bin/more
-is used.
+is used
+.Pq Nm zmore
+or
+.Pa /usr/bin/less
+.Pq Nm zless .
.El
.Sh SEE ALSO
.Xr compress 1 ,
else
compressed_pre = NULL;
- while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
+ while ((bin = fread(buf, 1, BUFSIZE, in)) != 0) {
if (tflag == 0 && (off_t)fwrite(buf, 1, bin, out) != bin) {
free(buf);
return -1;
bzero(xattrBuf, xattrBufLen);
result = getxattr(path, name, xattrBuf, xattrBufLen, 0, options);
if (result < 0)
- err(1, "SHA256_Path_XATTRs: getxattr");
+ err(1, "SHA256_Path_XATTRs getxattr of \"%s\" at path \"%s\" failed with error", name, path );
digest = SHA256_Data(xattrBuf, xattrBufLen, buf);
if (!digest)
char truncated[len];
if ((p = strrchr(*t, '/')) != NULL) {
- if (p[1] == '\0') { // trailing / -- treat as if not present
+ if (p[1] == '\0') { // one or more trailing / -- treat as if not present
+ for (; (p > *t) && (p[-1] == '/');) {
+ len--;
+ p--;
+ }
strlcpy(truncated, *t, len);
p = strrchr(truncated, '/');
if (p) {