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].
This commit is contained in:
parent
e2f0a0f35c
commit
a8de850f7b
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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 <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.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);
|
||||
|
Loading…
Reference in New Issue
Block a user