summaryrefslogtreecommitdiffstats
path: root/usr.bin/cksum
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1997-07-06 02:22:28 +0000
committerbde <bde@FreeBSD.org>1997-07-06 02:22:28 +0000
commita8de850f7b099919b206864302797257b8ebfa2a (patch)
tree0a8990a51faa085f0b34defeb1bb5b3607ea6179 /usr.bin/cksum
parente2f0a0f35c8c3ecbae359c67f0d5b3aac5ce43dc (diff)
downloadFreeBSD-src-a8de850f7b099919b206864302797257b8ebfa2a.zip
FreeBSD-src-a8de850f7b099919b206864302797257b8ebfa2a.tar.gz
Import Lite2's src/usr.bin/cksum. The Makefile is still on the vendor
branch and will temporarily give bogus hard links cksum[.1] -> sum[.1].
Diffstat (limited to 'usr.bin/cksum')
-rw-r--r--usr.bin/cksum/Makefile4
-rw-r--r--usr.bin/cksum/cksum.118
-rw-r--r--usr.bin/cksum/cksum.c45
3 files changed, 45 insertions, 22 deletions
diff --git a/usr.bin/cksum/Makefile b/usr.bin/cksum/Makefile
index d2f09b7..ee680bec 100644
--- a/usr.bin/cksum/Makefile
+++ b/usr.bin/cksum/Makefile
@@ -1,6 +1,8 @@
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
+# @(#)Makefile 8.2 (Berkeley) 4/28/95
PROG= cksum
SRCS= cksum.c crc.c print.c sum1.c sum2.c
+LINKS= ${BINDIR}/cksum ${BINDIR}/sum
+MLINKS= cksum.1 sum.1
.include <bsd.prog.mk>
diff --git a/usr.bin/cksum/cksum.1 b/usr.bin/cksum/cksum.1
index 7c2cc24..f5f292b 100644
--- a/usr.bin/cksum/cksum.1
+++ b/usr.bin/cksum/cksum.1
@@ -32,9 +32,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)cksum.1 8.1 (Berkeley) 6/29/93
+.\" @(#)cksum.1 8.2 (Berkeley) 4/28/95
.\"
-.Dd June 29, 1993
+.Dd April 28, 1995
.Dt CKSUM 1
.Os BSD 4.4
.Sh NAME
@@ -44,6 +44,8 @@
.Nm cksum
.Op Fl o Op \&1 \&| \&2
.Op Ar file ...
+.Nm sum
+.Op Ar file ...
.Sh DESCRIPTION
The
.Nm cksum
@@ -55,6 +57,14 @@ the total number of octets in the file and the file name.
If no file name is specified, the standard input is used and no file name
is written.
.Pp
+The
+.Nm sum
+utility is identical to the
+.Nm cksum
+utility, except that it defaults to using historic algorithm 1, as
+described below.
+It is provided for compatibility only.
+.Pp
The options are as follows:
.Bl -tag -width indent
.It Fl o
@@ -141,7 +151,9 @@ The bit sequence is complemented and the result is the CRC.
.Pp
The
.Nm cksum
-utility exits 0 on success, and >0 if an error occurs.
+and
+.Nm sum
+utilities exit 0 on success, and >0 if an error occurs.
.Sh SEE ALSO
The default calculation is identical to that given in pseudo-code
in the following
diff --git a/usr.bin/cksum/cksum.c b/usr.bin/cksum/cksum.c
index 3e66ca5..9b8e81a 100644
--- a/usr.bin/cksum/cksum.c
+++ b/usr.bin/cksum/cksum.c
@@ -41,17 +41,20 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)cksum.c 8.2 (Berkeley) 4/28/95";
#endif /* not lint */
#include <sys/cdefs.h>
#include <sys/types.h>
+
+#include <err.h>
+#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <stdio.h>
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
#include "extern.h"
void usage __P((void));
@@ -61,27 +64,35 @@ main(argc, argv)
int argc;
char **argv;
{
- extern int optind;
- u_long len, val;
register int ch, fd, rval;
- char *fn;
+ u_long len, val;
+ char *fn, *p;
int (*cfncn) __P((int, unsigned long *, unsigned long *));
void (*pfncn) __P((char *, unsigned long, unsigned long));
- cfncn = crc;
- pfncn = pcrc;
- while ((ch = getopt(argc, argv, "o:")) != EOF)
- switch(ch) {
+ if ((p = rindex(argv[0], '/')) == NULL)
+ p = argv[0];
+ else
+ ++p;
+ if (*p == 'c') {
+ cfncn = crc;
+ pfncn = pcrc;
+ } else {
+ cfncn = csum1;
+ pfncn = psum1;
+ }
+
+ while ((ch = getopt(argc, argv, "o:")) != -1)
+ switch (ch) {
case 'o':
- if (*optarg == '1') {
+ if (!strcmp(optarg, "1")) {
cfncn = csum1;
pfncn = psum1;
- } else if (*optarg == '2') {
+ } else if (!strcmp(optarg, "2")) {
cfncn = csum2;
pfncn = psum2;
} else {
- (void)fprintf(stderr,
- "cksum: illegal argument to -o option\n");
+ warnx("illegal argument to -o option");
usage();
}
break;
@@ -99,15 +110,13 @@ main(argc, argv)
if (*argv) {
fn = *argv++;
if ((fd = open(fn, O_RDONLY, 0)) < 0) {
- (void)fprintf(stderr, "cksum: %s: %s\n",
- fn, strerror(errno));
+ warn("%s", fn);
rval = 1;
continue;
}
}
if (cfncn(fd, &val, &len)) {
- (void)fprintf(stderr, "cksum: %s: %s\n",
- fn ? fn : "stdin", strerror(errno));
+ warn("%s", fn ? fn : "stdin");
rval = 1;
} else
pfncn(fn, val, len);
OpenPOWER on IntegriCloud