From f383e97b3f95842c6ff58e791aa34856880a1a41 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 29 Jun 2004 04:46:53 +0000 Subject: [PATCH] file_cmds-90.tar.gz --- chmod/chmod.1 | 5 +- chmod/chmod.c | 4 + chown/chown.8 | 10 +-- chown/chown.c | 12 ++- cp/cp.c | 5 +- cp/utils.c | 1 + install/Makefile.preamble | 4 - install/xinstall.c | 4 - ln/Makefile.postamble | 6 ++ ls/Makefile | 2 +- ls/ls.c | 6 -- ls/print.c | 4 - ls/stat_flags.c | 164 -------------------------------------- mknod/mknod.8 | 4 +- rm/Makefile.postamble | 5 ++ rm/Makefile.preamble | 2 - rm/rm.c | 11 --- tcopy/tcopy.1 | 38 +++++++-- tcopy/tcopy.c | 148 +++++++++++++++++----------------- touch/touch.1 | 10 +-- touch/touch.c | 8 ++ 21 files changed, 151 insertions(+), 302 deletions(-) delete mode 100644 ls/stat_flags.c diff --git a/chmod/chmod.1 b/chmod/chmod.1 index 8e5de74..d0b2917 100644 --- a/chmod/chmod.1 +++ b/chmod/chmod.1 @@ -43,7 +43,7 @@ .Nd change file modes .Sh SYNOPSIS .Nm -.Op Fl fhv +.Op Fl fv .Op Fl R Op Fl H | L | P .Ar mode .Ar @@ -80,9 +80,6 @@ Do not display a diagnostic message if .Nm could not modify the mode for .Va file . -.It Fl h -If the file is a symbolic link, change the mode of the link itself -rather than the file that the link points to. .It Fl v Cause .Nm diff --git a/chmod/chmod.c b/chmod/chmod.c index c38286d..c01c5dd 100644 --- a/chmod/chmod.c +++ b/chmod/chmod.c @@ -77,7 +77,11 @@ main(int argc, char *argv[]) set = NULL; omode = 0; Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; +#ifndef __APPLE__ while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1) +#else + while ((ch = getopt(argc, argv, "HLPRXfgorstuvwx")) != -1) +#endif switch (ch) { case 'H': Hflag = 1; diff --git a/chown/chown.8 b/chown/chown.8 index 18d467d..9f141bf 100644 --- a/chown/chown.8 +++ b/chown/chown.8 @@ -40,7 +40,7 @@ .Nd change file owner and group .Sh SYNOPSIS .Nm -.Op Fl fhv +.Op Fl fv .Oo .Fl R .Op Fl H | Fl L | Fl P @@ -48,7 +48,7 @@ .Ar owner Ns Op : Ns Ar group .Ar .Nm -.Op Fl fhv +.Op Fl fv .Oo .Fl R .Op Fl H | Fl L | Fl P @@ -59,9 +59,6 @@ The .Nm utility changes the user ID and/or the group ID of the specified files. -Symbolic links named by arguments are silently left unchanged unless -.Fl h -is used. .Pp The options are as follows: .Bl -tag -width Ds @@ -85,9 +82,6 @@ in the files instead of just the files themselves. .It Fl f Don't report any failure to change file owner or group, nor modify the exit status to reflect such failures. -.It Fl h -If the file is a symbolic link, change the user ID and/or the -group ID of the link itself. .It Fl v Cause .Nm diff --git a/chown/chown.c b/chown/chown.c index 464bf23..03305f5 100644 --- a/chown/chown.c +++ b/chown/chown.c @@ -84,7 +84,11 @@ main(int argc, char **argv) ischown = (strcmp(cp, "chown") == 0); Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; +#ifndef __APPLE__ while ((ch = getopt(argc, argv, "HLPRfhv")) != -1) +#else + while ((ch = getopt(argc, argv, "HLPRfv")) != -1) +#endif switch (ch) { case 'H': Hflag = 1; @@ -103,9 +107,11 @@ main(int argc, char **argv) case 'f': fflag = 1; break; +#ifndef __APPLE__ case 'h': hflag = 1; - break; + break; +#endif case 'v': vflag = 1; break; @@ -283,6 +289,10 @@ usage(void) " chown [-fhv] [-R [-H | -L | -P]] :group file ..."); else (void)fprintf(stderr, "%s\n", +#ifndef __APPLE__ "usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ..."); +#else + "usage: chgrp [-fv] [-R [-H | -L | -P]] group file ..."); +#endif exit(1); } diff --git a/cp/cp.c b/cp/cp.c index 6272d8e..43e094b 100644 --- a/cp/cp.c +++ b/cp/cp.c @@ -415,9 +415,8 @@ copy(char *argv[], enum op type, int fts_options) break; case S_IFDIR: if (!Rflag && !rflag) { - if (curr->fts_info == FTS_DP) - warnx("%s is a directory (not copied).", - curr->fts_path); + warnx("%s is a directory (not copied).", + curr->fts_path); (void)fts_set(ftsp, curr, FTS_SKIP); badcp = rval = 1; break; diff --git a/cp/utils.c b/cp/utils.c index b55bbc9..56256f9 100644 --- a/cp/utils.c +++ b/cp/utils.c @@ -90,6 +90,7 @@ copy_file(FTSENT *entp, int dne) if (nflag) { if (vflag) printf("%s not overwritten\n", to.p_path); + close(from_fd); return (0); } else if (iflag) { (void)fprintf(stderr, "overwrite %s? %s", diff --git a/install/Makefile.preamble b/install/Makefile.preamble index 7a86fc2..9e10e90 100644 --- a/install/Makefile.preamble +++ b/install/Makefile.preamble @@ -1,5 +1 @@ -vpath stat_flags.c ../ls - -CFILES += stat_flags.c - include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/install/xinstall.c b/install/xinstall.c index 2cb3e92..a98ca93 100644 --- a/install/xinstall.c +++ b/install/xinstall.c @@ -85,10 +85,6 @@ int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose; mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; char *suffix = BACKUP_SUFFIX; -#ifdef __APPLE__ -u_long string_to_flags __P((char **, u_long *, u_long *)); -#define strtofflags(x,y,z) string_to_flags((x),(y),(z)) -#endif void copy __P((int, char *, int, char *, off_t)); int compare __P((int, const char *, size_t, int, const char *, size_t)); int create_newfile __P((char *, int, struct stat *)); diff --git a/ln/Makefile.postamble b/ln/Makefile.postamble index 013b558..b347e1a 100644 --- a/ln/Makefile.postamble +++ b/ln/Makefile.postamble @@ -1 +1,7 @@ include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +after_install:: + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/link + mkdir -p "$(DSTROOT)/usr/share/man/man1" + ln -f "$(DSTROOT)/usr/share/man/man1/ln.1" "$(DSTROOT)/usr/share/man/man1/link.1" + diff --git a/ls/Makefile b/ls/Makefile index 6793f2b..33d8b5a 100644 --- a/ls/Makefile +++ b/ls/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool HFILES = extern.h ls.h -CFILES = cmp.c ls.c print.c stat_flags.c util.c +CFILES = cmp.c ls.c print.c util.c OTHERSRCS = Makefile Makefile.preamble Makefile.postamble ls.1 diff --git a/ls/ls.c b/ls/ls.c index 99f45b2..92e38b3 100644 --- a/ls/ls.c +++ b/ls/ls.c @@ -630,13 +630,7 @@ display(FTSENT *p, FTSENT *list) warnx("%s: %s", cur->fts_name, strerror(cur->fts_errno)); cur->fts_number = NO_PRINT; -#ifndef __APPLE__ - /* Don't count this as an error. This is for - * binary compatibility with Matlab installer script. - * 3252074 - */ rval = 1; -#endif continue; } /* diff --git a/ls/print.c b/ls/print.c index b3dd339..4962a95 100644 --- a/ls/print.c +++ b/ls/print.c @@ -49,9 +49,7 @@ __RCSID("$FreeBSD: src/bin/ls/print.c,v 1.57 2002/08/29 14:29:09 keramida Exp $" #include #include #include -#ifndef __APPLE__ #include -#endif /* __APPLE__ */ #include #include #include @@ -379,10 +377,8 @@ printtime(time_t ftime) const char *format; static int d_first = -1; -#ifndef __APPLE__ if (d_first < 0) d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); -#endif /* __APPLE__ */ if (now == 0) now = time(NULL); diff --git a/ls/stat_flags.c b/ls/stat_flags.c deleted file mode 100644 index e46a3e8..0000000 --- a/ls/stat_flags.c +++ /dev/null @@ -1,164 +0,0 @@ -/* $NetBSD: stat_flags.c,v 1.6 1997/07/20 18:53:12 christos Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 -#ifndef lint -#if 0 -static char sccsid[] = "@(#)stat_flags.c 8.2 (Berkeley) 7/28/94"; -#else -__RCSID("$NetBSD: stat_flags.c,v 1.6 1997/07/20 18:53:12 christos Exp $"); -#endif -#endif /* not lint */ - -#include -#include - -#include -#include -#include - -#include "ls.h" -#include "extern.h" - -#define SAPPEND(s) { \ - if (prefix != NULL) \ - (void)strcat(string, prefix); \ - (void)strcat(string, s); \ - prefix = ","; \ -} - -/* - * flags_to_string -- - * Convert stat flags to a comma-separated string. If no flags - * are set, return the default string. - */ -char * -flags_to_string(flags, def) - u_long flags; - char *def; -{ - static char string[128]; - char *prefix; - - string[0] = '\0'; - prefix = NULL; - if (flags & UF_APPEND) - SAPPEND("uappnd"); - if (flags & UF_IMMUTABLE) - SAPPEND("uchg"); - if (flags & UF_NODUMP) - SAPPEND("nodump"); - if (flags & UF_OPAQUE) - SAPPEND("opaque"); - if (flags & SF_APPEND) - SAPPEND("sappnd"); - if (flags & SF_ARCHIVED) - SAPPEND("arch"); - if (flags & SF_IMMUTABLE) - SAPPEND("schg"); - return (prefix == NULL && def != NULL ? def : string); -} - -#define TEST(a, b, f) { \ - if (!memcmp(a, b, sizeof(b))) { \ - if (clear) { \ - if (clrp) \ - *clrp |= (f); \ - } else if (setp) \ - *setp |= (f); \ - break; \ - } \ -} - -/* - * string_to_flags -- - * Take string of arguments and return stat flags. Return 0 on - * success, 1 on failure. On failure, stringp is set to point - * to the offending token. - */ -int -string_to_flags(stringp, setp, clrp) - char **stringp; - u_long *setp, *clrp; -{ - int clear; - char *string, *p; - - clear = 0; - if (setp) - *setp = 0; - if (clrp) - *clrp = 0; - string = *stringp; - while ((p = strsep(&string, "\t ,")) != NULL) { - *stringp = p; - if (*p == '\0') - continue; - if (p[0] == 'n' && p[1] == 'o') { - clear = 1; - p += 2; - } - switch (p[0]) { - case 'a': - TEST(p, "arch", SF_ARCHIVED); - TEST(p, "archived", SF_ARCHIVED); - return (1); - case 'd': - clear = !clear; - TEST(p, "dump", UF_NODUMP); - return (1); - case 'o': - TEST(p, "opaque", UF_OPAQUE); - return (1); - case 's': - TEST(p, "sappnd", SF_APPEND); - TEST(p, "sappend", SF_APPEND); - TEST(p, "schg", SF_IMMUTABLE); - TEST(p, "schange", SF_IMMUTABLE); - TEST(p, "simmutable", SF_IMMUTABLE); - return (1); - case 'u': - TEST(p, "uappnd", UF_APPEND); - TEST(p, "uappend", UF_APPEND); - TEST(p, "uchg", UF_IMMUTABLE); - TEST(p, "uchange", UF_IMMUTABLE); - TEST(p, "uimmutable", UF_IMMUTABLE); - /* FALLTHROUGH */ - default: - return (1); - } - } - return (0); -} diff --git a/mknod/mknod.8 b/mknod/mknod.8 index 7a1517d..d68dab1 100644 --- a/mknod/mknod.8 +++ b/mknod/mknod.8 @@ -45,12 +45,12 @@ .Ar name .Op Cm c | Cm b .Ar major minor -.Nm "" +.Nm .Op Fl F Ar format .Ar name .Op Cm c | Cm b .Ar major unit subunit -.Nm "" +.Nm .Ar name .Op Cm c | Cm b .Ar number diff --git a/rm/Makefile.postamble b/rm/Makefile.postamble index 013b558..bc9f08f 100644 --- a/rm/Makefile.postamble +++ b/rm/Makefile.postamble @@ -1 +1,6 @@ include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +after_install:: + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/unlink + mkdir -p "$(DSTROOT)/usr/share/man/man1" + ln -f "$(DSTROOT)/usr/share/man/man1/rm.1" "$(DSTROOT)/usr/share/man/man1/unlink.1" diff --git a/rm/Makefile.preamble b/rm/Makefile.preamble index 48df90e..9e10e90 100644 --- a/rm/Makefile.preamble +++ b/rm/Makefile.preamble @@ -1,3 +1 @@ -vpath stat_flags.c ../ls -CFILES += stat_flags.c include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/rm/rm.c b/rm/rm.c index 63666a9..7997af5 100644 --- a/rm/rm.c +++ b/rm/rm.c @@ -70,15 +70,6 @@ void rm_overwrite __P((char *, struct stat *)); void rm_tree __P((char **)); void usage __P((void)); -#ifdef __APPLE__ -/* We lack fflagstostr(), but ls has a flags_to_string function - * that does the same thing. So... We really use that. - */ -char * flags_to_string(u_long, char *); -#define fflagstostr(x) flags_to_string((x), NULL) - -#endif - /* * rm -- * This rm is different from historic rm's, but is expected to match @@ -456,9 +447,7 @@ check(path, name, sp) group_from_gid(sp->st_gid, 0), *flagsp ? flagsp : "", *flagsp ? " " : "", path); -#ifndef __APPLE__ free(flagsp); -#endif } (void)fflush(stderr); diff --git a/tcopy/tcopy.1 b/tcopy/tcopy.1 index ed27627..880d18b 100644 --- a/tcopy/tcopy.1 +++ b/tcopy/tcopy.1 @@ -1,5 +1,3 @@ -.\" $NetBSD: tcopy.1,v 1.5 1997/10/20 00:35:14 lukem Exp $ -.\" .\" Copyright (c) 1985, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -32,10 +30,11 @@ .\" SUCH DAMAGE. .\" .\" @(#)tcopy.1 8.2 (Berkeley) 4/17/94 +.\" $FreeBSD: src/usr.bin/tcopy/tcopy.1,v 1.15 2003/09/05 15:28:09 roam Exp $ .\" .Dd April 17, 1994 .Dt TCOPY 1 -.Os BSD 4.3 +.Os .Sh NAME .Nm tcopy .Nd copy and/or verify mag tapes @@ -46,12 +45,14 @@ .Oo Ar src Op Ar dest .Oc .Sh DESCRIPTION +The .Nm -is designed to copy magnetic tapes. The only assumption made +utility is designed to copy magnetic tapes. The only assumption made about the tape is that there are two tape marks at the end. +The .Nm -with only a source tape -.Pf ( Ar /dev/rst0 +utility with only a source tape +.Pf ( Ar /dev/sa0 by default) specified will print information about the sizes of records and tape files. If a destination is specified a copy will be made of the source tape. The blocking on the @@ -71,7 +72,7 @@ Specify a maximum block size, .Ar maxblk . .It Fl v Given the two tapes, -.ar src +.Ar src and .Ar dest verify that they are identical. @@ -89,3 +90,26 @@ The .Nm command appeared in .Bx 4.3 . +.Sh BUGS +.Bl -item +.It +Writing an image of a tape to a file does not preserve much more than +the raw data. +Block size(s) and tape EOF marks are lost which would +otherwise be preserved in a tape-to-tape copy. +.It +EOD is determined by two sequential EOF marks with no data between. +There are old systems which typically wrote three EOF's between tape +files. +The +.Nm +utility will erroneously stop copying early in this case. +.It +When using the copy/verify option \-c +.Nm +does not rewind the tapes prior to start. +A rewind is performed +after writing prior to the verification stage. +If one doesn't start +at BOT then the comparison may not be of the intended data. +.El diff --git a/tcopy/tcopy.c b/tcopy/tcopy.c index 297ad01..8f70cbe 100644 --- a/tcopy/tcopy.c +++ b/tcopy/tcopy.c @@ -1,7 +1,5 @@ -/* $NetBSD: tcopy.c,v 1.8 1998/08/25 20:59:41 ross Exp $ */ - /* - * Copyright (c) 1985, 1987, 1993, 1995 + * Copyright (c) 1985, 1987, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,17 +32,16 @@ */ #include + #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1985, 1987, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); -#endif /* not lint */ +static const char copyright[] = +"@(#) Copyright (c) 1985, 1987, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif #ifndef lint -#if 0 -static char sccsid[] = "@(#)tcopy.c 8.3 (Berkeley) 1/23/95"; +static const char sccsid[] = "@(#)tcopy.c 8.2 (Berkeley) 4/17/94"; #endif -__RCSID("$NetBSD: tcopy.c,v 1.8 1998/08/25 20:59:41 ross Exp $"); -#endif /* not lint */ #include #include @@ -53,9 +50,10 @@ __RCSID("$NetBSD: tcopy.c,v 1.8 1998/08/25 20:59:41 ross Exp $"); #include #include -#include #include +#include #include +#include #include #include #include @@ -65,30 +63,29 @@ __RCSID("$NetBSD: tcopy.c,v 1.8 1998/08/25 20:59:41 ross Exp $"); #define NOCOUNT (-2) int filen, guesslen, maxblk = MAXREC; -long lastrec, record; -off_t size, tsize; -FILE *msg = stdout; +u_int64_t lastrec, record, size, tsize; +FILE *msg; -void *getspace __P((int)); -void intr __P((int)); -int main __P((int, char **)); -void usage __P((void)); -void verify __P((int, int, char *)); -void writeop __P((int, int)); +void *getspace(int); +void intr(int); +static void usage(void); +void verify(int, int, char *); +void writeop(int, int); +void rewind_tape(int); int main(argc, argv) int argc; char *argv[]; { - int ch, needeof, nw, inp, outp; - ssize_t lastnread, nread; + register int lastnread, nread, nw, inp, outp; enum {READ, VERIFY, COPY, COPYVERIFY} op = READ; sig_t oldsig; - char *buff, *inf; + int ch, needeof; + char *buff; + const char *inf; - outp = 0; - inf = NULL; + msg = stdout; guesslen = 1; while ((ch = getopt(argc, argv, "cs:vx")) != -1) switch((char)ch) { @@ -132,16 +129,15 @@ main(argc, argv) op = COPY; inf = argv[0]; if ((outp = open(argv[1], op == VERIFY ? O_RDONLY : - op == COPY ? O_WRONLY : O_RDWR, DEFFILEMODE)) < 0) { - err(3, argv[1]); - } + op == COPY ? O_WRONLY : O_RDWR, DEFFILEMODE)) < 0) + err(3, "%s", argv[1]); break; default: usage(); } if ((inp = open(inf, O_RDONLY, 0)) < 0) - err(1, inf); + err(1, "%s", inf); buff = getspace(maxblk); @@ -161,21 +157,20 @@ main(argc, argv) if (nread >= 0) goto r1; } - err(1, "read error, file %d, record %ld", - filen, record); + err(1, "read error, file %d, record %qu", filen, record); } else if (nread != lastnread) { if (lastnread != 0 && lastnread != NOCOUNT) { if (lastrec == 0 && nread == 0) - fprintf(msg, "%ld records\n", record); + fprintf(msg, "%qu records\n", record); else if (record - lastrec > 1) - fprintf(msg, "records %ld to %ld\n", + fprintf(msg, "records %qu to %qu\n", lastrec, record); else - fprintf(msg, "record %ld\n", lastrec); + fprintf(msg, "record %qu\n", lastrec); } if (nread != 0) - fprintf(msg, "file %d: block size %ld: ", - filen, (long)nread); + fprintf(msg, "file %d: block size %d: ", + filen, nread); (void) fflush(stdout); lastrec = record; } @@ -188,19 +183,13 @@ r1: guesslen = 0; } nw = write(outp, buff, nread); if (nw != nread) { - int error = errno; - fprintf(stderr, - "write error, file %d, record %ld: ", - filen, record); - if (nw == -1) - fprintf(stderr, - ": %s", strerror(error)); - else - fprintf(stderr, - "write (%d) != read (%ld)\n", - nw, (long)nread); - fprintf(stderr, "copy aborted\n"); - exit(5); + if (nw == -1) { + warn("write error, file %d, record %qu", filen, record); + } else { + warnx("write error, file %d, record %qu", filen, record); + warnx("write (%d) != read (%d)", nw, nread); + } + errx(5, "copy aborted"); } } size += nread; @@ -211,8 +200,8 @@ r1: guesslen = 0; break; } fprintf(msg, - "file %d: eof after %ld records: %qd bytes\n", - filen, record, (long long)size); + "file %d: eof after %qu records: %qu bytes\n", + filen, record, size); needeof = 1; filen++; tsize += size; @@ -221,14 +210,14 @@ r1: guesslen = 0; } lastnread = nread; } - fprintf(msg, "total length: %qd bytes\n", (long long)tsize); + fprintf(msg, "total length: %qu bytes\n", tsize); (void)signal(SIGINT, oldsig); if (op == COPY || op == COPYVERIFY) { writeop(outp, MTWEOF); writeop(outp, MTWEOF); if (op == COPYVERIFY) { - writeop(outp, MTREW); - writeop(inp, MTREW); + rewind_tape(outp); + rewind_tape(inp); verify(inp, outp, buff); } } @@ -237,11 +226,11 @@ r1: guesslen = 0; void verify(inp, outp, outb) - int inp, outp; - char *outb; + register int inp, outp; + register char *outb; { - int eot, inmaxblk, inn, outmaxblk, outn; - char *inb; + register int eot, inmaxblk, inn, outmaxblk, outn; + register char *inb; inb = getspace(maxblk); inmaxblk = outmaxblk = maxblk; @@ -274,15 +263,13 @@ r2: if (inn != outn) { } if (!inn) { if (eot++) { - fprintf(msg, "%s: tapes are identical.\n", - "tcopy"); + fprintf(msg, "tcopy: tapes are identical.\n"); return; } } else { - if (memcmp(inb, outb, inn)) { + if (bcmp(inb, outb, inn)) { fprintf(msg, - "%s: tapes have different data.\n", - "tcopy"); + "tcopy: tapes have different data.\n"); break; } eot = 0; @@ -293,16 +280,16 @@ r2: if (inn != outn) { void intr(signo) - int signo; + int signo __unused; { if (record) { if (record - lastrec > 1) - fprintf(msg, "records %ld to %ld\n", lastrec, record); + fprintf(msg, "records %qu to %qu\n", lastrec, record); else - fprintf(msg, "record %ld\n", lastrec); + fprintf(msg, "record %qu\n", lastrec); } - fprintf(msg, "interrupt at file %d: record %ld\n", filen, record); - fprintf(msg, "total length: %qd bytes\n", (long long)(tsize + size)); + fprintf(msg, "interrupt at file %d: record %qu\n", filen, record); + fprintf(msg, "total length: %ju bytes\n", (uintmax_t)(tsize + size)); exit(1); } @@ -314,7 +301,6 @@ getspace(blk) if ((bp = malloc((size_t)blk)) == NULL) errx(11, "no memory"); - return (bp); } @@ -330,10 +316,28 @@ writeop(fd, type) err(6, "tape op"); } -void +static void usage() { - - fprintf(stderr, "usage: tcopy [-cvx] [-s maxblk] src [dest]\n"); + fprintf(stderr, "usage: tcopy [-cvx] [-s maxblk] [src [dest]]\n"); exit(1); } + +void +rewind_tape(int fd) +{ + struct stat sp; + + if(fstat(fd, &sp)) + errx(12, "fstat in rewind"); + + /* + * don't want to do tape ioctl on regular files: + */ + if( S_ISREG(sp.st_mode) ) { + if( lseek(fd, 0, SEEK_SET) == -1 ) + errx(13, "lseek"); + } else + /* assume its a tape */ + writeop(fd, MTREW); +} diff --git a/touch/touch.1 b/touch/touch.1 index e15f9a6..cf6d863 100644 --- a/touch/touch.1 +++ b/touch/touch.1 @@ -43,7 +43,7 @@ .Nd change file access and modification times .Sh SYNOPSIS .Nm -.Op Fl acfhm +.Op Fl acfm .Op Fl r Ar file .Op Fl t Ar [[CC]YY]MMDDhhmm[.SS] .Ar @@ -70,14 +70,6 @@ No error messages are displayed and the exit value is not affected. .It Fl f Attempt to force the update, even if the file permissions do not currently permit it. -.It Fl h -If the file is a symbolic link, change the times of the link -itself rather than the file that the link points to. -Note that -.Fl h -implies -.Fl c -and thus will not create any new files. .It Fl m Change the modification time of the file. The access time of the file is not changed unless the diff --git a/touch/touch.c b/touch/touch.c index 5436285..77ca8e9 100644 --- a/touch/touch.c +++ b/touch/touch.c @@ -80,7 +80,11 @@ main(int argc, char *argv[]) if (gettimeofday(&tv[0], NULL)) err(1, "gettimeofday"); +#ifndef __APPLE__ while ((ch = getopt(argc, argv, "acfhmr:t:")) != -1) +#else + while ((ch = getopt(argc, argv, "acfmr:t:")) != -1) +#endif switch(ch) { case 'a': aflag = 1; @@ -350,6 +354,10 @@ err: rval = 1; void usage(void) { +#ifndef __APPLE__ (void)fprintf(stderr, "usage: touch [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); +#else + (void)fprintf(stderr, "usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...\n"); +#endif exit(1); } -- 2.45.2