]> git.saurik.com Git - apple/file_cmds.git/commitdiff
file_cmds-272.tar.gz macos-1013 macos-10131 macos-10132 macos-10133 macos-10134 macos-10135 macos-10136 v272
authorApple <opensource@apple.com>
Thu, 20 Apr 2017 19:47:46 +0000 (19:47 +0000)
committerApple <opensource@apple.com>
Thu, 20 Apr 2017 19:47:46 +0000 (19:47 +0000)
14 files changed:
cp/cp.1
cp/cp.c
cp/extern.h
cp/utils.c
dd/install_symlink.sh
file_cmds.xcodeproj/project.pbxproj
gzip/futimens.c [new file with mode: 0644]
gzip/gzip.1
gzip/gzip.c
gzip/zmore
gzip/zmore.1
gzip/zuncompress.c
mtree/commoncrypto.c
rm/rm.c

diff --git a/cp/cp.1 b/cp/cp.1
index 6f5507d17044e2059d4f9ac09cb7a4072ce33547..8c346c7de6304d0ad130543ad7843d81c173ecce 100644 (file)
--- a/cp/cp.1
+++ b/cp/cp.1
@@ -192,6 +192,8 @@ Cause
 to be verbose, showing files as they are copied.
 .It Fl X
 Do not copy Extended Attributes (EAs) or resource forks.
 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
 .El
 .Pp
 For each destination file that already exists, its contents are
diff --git a/cp/cp.c b/cp/cp.c
index 7af6bbcf945fb524d48dd0fe406c40d7546214f9..c856fd995d74d95802cee2ce10b0c054d19baaa1 100644 (file)
--- a/cp/cp.c
+++ b/cp/cp.c
@@ -95,6 +95,7 @@ int fflag, iflag, nflag, pflag, vflag;
 int Xflag;
 #endif /* __APPLE__ */
 static int Rflag, rflag;
 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 };
 volatile sig_atomic_t info;
 
 enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -111,8 +112,11 @@ main(int argc, char *argv[])
        char *target;
 
        Hflag = Lflag = Pflag = 0;
        char *target;
 
        Hflag = Lflag = Pflag = 0;
-       while ((ch = getopt(argc, argv, "HLPRXafinprv")) != -1)
+       while ((ch = getopt(argc, argv, "cHLPRXafinprv")) != -1)
                switch (ch) {
                switch (ch) {
+               case 'c':
+                       cflag = 1;
+                       break;
                case 'H':
                        Hflag = 1;
                        Lflag = Pflag = 0;
                case 'H':
                        Hflag = 1;
                        Lflag = Pflag = 0;
@@ -174,6 +178,10 @@ main(int argc, char *argv[])
        if (argc < 2)
                usage();
 
        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)
        fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
        if (rflag) {
                if (Rflag)
index 10a52117f36112717557462b4e17c3b4488b3cc7..c0ca0bcbe667863d8e255a90ac7ec145baef11cf 100644 (file)
@@ -41,6 +41,7 @@ extern int fflag, iflag, nflag, pflag, vflag;
 #ifdef __APPLE__
 extern int Xflag;
 #endif /* __APPLE__ */
 #ifdef __APPLE__
 extern int Xflag;
 #endif /* __APPLE__ */
+extern int cflag;
 extern volatile sig_atomic_t info;
 
 __BEGIN_DECLS
 extern volatile sig_atomic_t info;
 
 __BEGIN_DECLS
index a2d031df5fbd0c96ac585fd434b0563b68004f58..afc525adc18115f04a982f77f790c9336433e797 100644 (file)
@@ -59,6 +59,8 @@ __FBSDID("$FreeBSD: src/bin/cp/utils.c,v 1.46 2005/09/05 04:36:08 csjp Exp $");
 #include <string.h>
 #include <sys/mount.h>
 #include <get_compat.h> 
 #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__ */
 #else 
 #define COMPAT_MODE(a,b) (1)
 #endif /* __APPLE__ */
@@ -118,6 +120,15 @@ copy_file(const FTSENT *entp, int dne)
                        }
                }
                
                        }
                }
                
+               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);
                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);
@@ -140,9 +151,19 @@ copy_file(const FTSENT *entp, int dne)
                            /* 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));
                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 (to_fd == -1) {
                warn("%s", to.p_path);
@@ -497,13 +518,13 @@ usage(void)
 
        if (COMPAT_MODE("bin/cp", "unix2003")) {
        (void)fprintf(stderr, "%s\n%s\n",
 
        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",
 "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);
 "target_directory");
        }
        exit(EX_USAGE);
index 4b8cd15505245396f970bce8e3dcdf1eabc6260f..7e8665f68b24998d8e804b893ecf1653612297b1 100644 (file)
@@ -3,7 +3,7 @@ set -e
 set -x
 
 case "$PLATFORM_NAME" in
 set -x
 
 case "$PLATFORM_NAME" in
-iphoneos|appletvos|watchos)
+iphoneos|appletvos|watchos|bridgeos)
     ln -hfs /usr/local/bin/dd "$DSTROOT"/bin/dd
     ;;
 macosx)
     ln -hfs /usr/local/bin/dd "$DSTROOT"/bin/dd
     ;;
 macosx)
index eddbd0afaaca6078f915ebffdabad701fd535ce0..be7b451154e851a061c038e3f2f3d43bd3d4eccd 100644 (file)
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
 /* 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 */; };
                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>"; };
 
 /* 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; };
                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 = (
                FDAD947F1808BB3A00B4D5A0 /* gzip */ = {
                        isa = PBXGroup;
                        children = (
+                               3E59B9301D4A767600D3128C /* futimens.c */,
                                FDAD94801808BB3A00B4D5A0 /* gzexe */,
                                FDAD94811808BB3A00B4D5A0 /* gzexe.1 */,
                                FDAD94821808BB3A00B4D5A0 /* gzip.1 */,
                                FDAD94801808BB3A00B4D5A0 /* gzexe */,
                                FDAD94811808BB3A00B4D5A0 /* gzexe.1 */,
                                FDAD94821808BB3A00B4D5A0 /* gzip.1 */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               3E59B9311D4A767600D3128C /* futimens.c in Sources */,
                                FDAD949F1808BBB900B4D5A0 /* gzip.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                                FDAD949F1808BBB900B4D5A0 /* gzip.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/gzip/futimens.c b/gzip/futimens.c
new file mode 100644 (file)
index 0000000..08345c3
--- /dev/null
@@ -0,0 +1,100 @@
+/*-
+ * 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));
+}
index 0157563bd4f2425ad384456b9877141d8805c523..98e0ea258913bf2f03878d03cca25bd787c33f47 100644 (file)
@@ -1,4 +1,4 @@
-.\"    $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.
 .\"
 .\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
 .\" All rights reserved.
@@ -24,8 +24,8 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\" 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
 .Dt GZIP 1
 .Os
 .Sh NAME
@@ -101,17 +101,14 @@ then both the
 and
 .Fl d
 options are enabled.
 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
 .Pp
 This version of
 .Nm
 is also capable of decompressing files compressed using
-.Xr compress 1
+.Xr compress 1 ,
+.Xr bzip2 1 ,
 or
 or
-.Xr bzip2 1 .
+.Xr xz 1 .
 .Sh OPTIONS
 The following options are available:
 .Bl -tag -width XXrXXXrecursiveX
 .Sh OPTIONS
 The following options are available:
 .Bl -tag -width XXrXXXrecursiveX
@@ -139,7 +136,7 @@ option, allowing non-compressed data to pass through unchanged.
 .It Fl h , -help
 This option prints a usage summary and exits.
 .It Fl k , -keep
 .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
 or decompression.
 .It Fl L , -license
 This option prints
@@ -186,13 +183,18 @@ is set, it is parsed as a white-space separated list of options
 handled before any options on the command line.
 Options on the command line will override anything in
 .Ev GZIP .
 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 ,
 .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
 .Sh HISTORY
 The
 .Nm
@@ -219,12 +221,12 @@ and first appeared in
 This implementation of
 .Nm
 was written by
 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
 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
 .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
 This limitation also applies to
 .Fl l
 option of
index e25262ce998a9fe57aedc2406f497021a9e126df..3d272667f710abe589d0417cdcb7e82c1afca5cf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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
 
 /*-
  * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
  Matthew R. Green.  All rights reserved.");
 #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 */
 
 /*
 #endif /* not lint */
 
 /*
@@ -69,6 +69,7 @@ __FBSDID("$FreeBSD: src/usr.bin/gzip/gzip.c,v 1.25 2011/10/10 06:37:32 delphij E
 #include <sys/attr.h>
 #include <copyfile.h>
 #include <get_compat.h>
 #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 */
 #endif /* __APPLE__ */
 
 /* what type of file are we dealing with */
@@ -167,7 +168,7 @@ static suffixes_t suffixes[] = {
 #ifdef __APPLE__
 static const char      gzip_version[] = "Apple gzip " GZIP_APPLE_VERSION;
 #else
 #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
 #endif
 
 #ifndef SMALL
@@ -831,6 +832,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
                                if (in_tot > 0) {
                                        maybe_warnx("%s: trailing garbage "
                                                    "ignored", filename);
                                if (in_tot > 0) {
                                        maybe_warnx("%s: trailing garbage "
                                                    "ignored", filename);
+                                       exit_value = 2;
                                        goto stop;
                                }
                                maybe_warnx("input not gziped (MAGIC0)");
                                        goto stop;
                                }
                                maybe_warnx("input not gziped (MAGIC0)");
@@ -1091,7 +1093,7 @@ out2:
 static void
 copymodes(int fd, const struct stat *sbp, const char *file)
 {
 static void
 copymodes(int fd, const struct stat *sbp, const char *file)
 {
-       struct timeval times[2];
+       struct timespec times[2];
        struct stat sb;
 
        /*
        struct stat sb;
 
        /*
@@ -1120,14 +1122,14 @@ copymodes(int fd, const struct stat *sbp, const char *file)
                maybe_warn("couldn't fchmod: %s", file);
 
 #ifdef __APPLE__
                maybe_warn("couldn't fchmod: %s", file);
 
 #ifdef __APPLE__
-       TIMESPEC_TO_TIMEVAL(&times[0], &sb.st_atimespec);
-       TIMESPEC_TO_TIMEVAL(&times[1], &sb.st_mtimespec);
+       times[0] = sb.st_atimespec;
+       times[1] = sb.st_mtimespec;
 #else
 #else
-       TIMESPEC_TO_TIMEVAL(&times[0], &sb.st_atim);
-       TIMESPEC_TO_TIMEVAL(&times[1], &sb.st_mtim);
+       times[0] = sb.st_atim;
+       times[1] = sb.st_mtim;
 #endif
 #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)
 
        /* only try flags if they exist already */
         if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
@@ -1412,7 +1414,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
 #ifndef SMALL
        ssize_t rv;
        time_t timestamp = 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 */
 #endif
 
        /* gather the old name info */
@@ -1467,21 +1469,33 @@ file_uncompress(char *file, char *outfile, size_t outsize)
                timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
 
                if (header1[3] & ORIG_NAME) {
                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 (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 */
                                /* 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), 
                                if (dp == NULL)
                                        dp = file;
                                else
                                        dp++;
                                snprintf(outfile, outsize, "%.*s%.*s",
                                                (int) (dp - file), 
-                                               file, (int) rbytes, name);
+                                               file, (int) rbytes, nf);
                        }
                }
        }
                        }
                }
        }
@@ -1827,7 +1841,7 @@ handle_stdout(void)
                return;
        }
 #endif
                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
        ret = fstat(STDIN_FILENO, &sb);
 
 #ifndef SMALL
@@ -2188,9 +2202,9 @@ display_license(void)
 {
 
 #ifdef __APPLE__
 {
 
 #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
 #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);
 #endif
        fprintf(stderr, "%s\n", gzip_copyright);
        exit(0);
index 6b55c77ef2b9599e2a2bb37e43ef7c4ec56c10e8..dbdbd3f8bde14a9c47b0391220b362117041c5b4 100644 (file)
@@ -1,7 +1,8 @@
 #!/bin/sh -
 #
 #!/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>
 #
 #-
 # 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.
 #
 # 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=
 
 # Pull out any command line flags so we can pass them to more/less
 flags=
@@ -48,15 +43,21 @@ while test $# -ne 0; do
        esac
 done
 
        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
 # 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
        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
        prev="$1"
        shift
        if tty -s && test -n "$oterm" -a $# -gt 0; then
index 19e7a0385e3d5f4cf6b1d5ef83cab40fc0394565..4723f224ae26c53bfe21c77ba407065be68bc01e 100644 (file)
@@ -1,5 +1,5 @@
-.\"    $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>
 .\"
 .\"
 .\" 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.
 .\"
 .\" 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
 .Dt ZMORE 1
 .Os
 .Sh NAME
-.Nm zmore
+.Nm zmore ,
+.Nm zless
 .Nd view compressed files
 .Sh SYNOPSIS
 .Nm zmore
 .Op Ar flags
 .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
 .Sh DESCRIPTION
 .Nm
 is a filter that allows the viewing of files compressed with Lempel-Ziv
@@ -51,6 +55,14 @@ that are specified are passed to the user's preferred
 .Pa /usr/bin/more
 by default).
 .Pp
 .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:
 When multiple files are specified,
 .Nm
 will pause at the end of each file and present the following prompt to the user:
@@ -86,7 +98,11 @@ style compression since there is no suffix on which to make a decision.
 Program used to display files.
 If unset,
 .Pa /usr/bin/more
 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 ,
 .El
 .Sh SEE ALSO
 .Xr compress 1 ,
index 454f05bc34da91d2d7fb778875385a801ec441c0..06df5976fb6c9991b50dae4bf7653585ebb6eb8b 100644 (file)
@@ -145,7 +145,7 @@ zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
        else
                compressed_pre = NULL;
 
        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;
                if (tflag == 0 && (off_t)fwrite(buf, 1, bin, out) != bin) {
                        free(buf);
                        return -1;
index 88efada8db3785118aec86c32505ec4d6fa6ad96..f7556312fda56401bc6eefd5341b4c812197302b 100644 (file)
@@ -143,7 +143,7 @@ char *SHA256_Path_XATTRs(char *path, char *buf)
                        bzero(xattrBuf, xattrBufLen);
                        result = getxattr(path, name, xattrBuf, xattrBufLen, 0, options);
                        if (result < 0)
                        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)
                        
                        digest = SHA256_Data(xattrBuf, xattrBufLen, buf);
                        if (!digest)
diff --git a/rm/rm.c b/rm/rm.c
index ec13b2a4f50f05ac787ddcb42cf655b00b00743a..9022802d5f11ffb26ac5dd24339081089815c1ea 100644 (file)
--- a/rm/rm.c
+++ b/rm/rm.c
@@ -534,7 +534,11 @@ checkdot(argv)
                char truncated[len];
 
                if ((p = strrchr(*t, '/')) != NULL) {
                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) {
                                strlcpy(truncated, *t, len);
                                p = strrchr(truncated, '/');
                                if (p) {