cksum.c (1c8af8787354e20c2b38cab5801698133ff8b403) cksum.c (f8a42d82e9fff548028285e4d6c828ce0b6a9b63)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * James W. Williams of NASA Goddard Space Flight Center.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * James W. Williams of NASA Goddard Space Flight Center.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
35 */
36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1991, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93";
45#endif /* not lint */
46
47#include <sys/cdefs.h>
48#include <sys/types.h>
37 */
38
39#ifndef lint
40static char copyright[] =
41"@(#) Copyright (c) 1991, 1993\n\
42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44
45#ifndef lint
46static char sccsid[] = "@(#)cksum.c 8.1 (Berkeley) 6/6/93";
47#endif /* not lint */
48
49#include <sys/cdefs.h>
50#include <sys/types.h>
51#include <err.h>
52#include <errno.h>
49#include <fcntl.h>
53#include <fcntl.h>
50#include <unistd.h>
51#include <stdio.h>
54#include <stdio.h>
52#include <errno.h>
53#include <stdlib.h>
54#include <string.h>
55#include <stdlib.h>
56#include <string.h>
57#include <unistd.h>
55#include "extern.h"
56
58#include "extern.h"
59
57void usage __P((void));
60static void usage __P((void));
58
59int
60main(argc, argv)
61 int argc;
62 char **argv;
63{
64 extern int optind;
65 u_long len, val;

--- 9 unchanged lines hidden (view full) ---

75 case 'o':
76 if (*optarg == '1') {
77 cfncn = csum1;
78 pfncn = psum1;
79 } else if (*optarg == '2') {
80 cfncn = csum2;
81 pfncn = psum2;
82 } else {
61
62int
63main(argc, argv)
64 int argc;
65 char **argv;
66{
67 extern int optind;
68 u_long len, val;

--- 9 unchanged lines hidden (view full) ---

78 case 'o':
79 if (*optarg == '1') {
80 cfncn = csum1;
81 pfncn = psum1;
82 } else if (*optarg == '2') {
83 cfncn = csum2;
84 pfncn = psum2;
85 } else {
83 (void)fprintf(stderr,
84 "cksum: illegal argument to -o option\n");
86 warnx("illegal argument to -o option");
85 usage();
86 }
87 break;
88 case '?':
89 default:
90 usage();
91 }
92 argc -= optind;
93 argv += optind;
94
95 fd = STDIN_FILENO;
96 fn = NULL;
97 rval = 0;
98 do {
99 if (*argv) {
100 fn = *argv++;
101 if ((fd = open(fn, O_RDONLY, 0)) < 0) {
87 usage();
88 }
89 break;
90 case '?':
91 default:
92 usage();
93 }
94 argc -= optind;
95 argv += optind;
96
97 fd = STDIN_FILENO;
98 fn = NULL;
99 rval = 0;
100 do {
101 if (*argv) {
102 fn = *argv++;
103 if ((fd = open(fn, O_RDONLY, 0)) < 0) {
102 (void)fprintf(stderr, "cksum: %s: %s\n",
103 fn, strerror(errno));
104 warn("%s", fn);
104 rval = 1;
105 continue;
106 }
107 }
108 if (cfncn(fd, &val, &len)) {
105 rval = 1;
106 continue;
107 }
108 }
109 if (cfncn(fd, &val, &len)) {
109 (void)fprintf(stderr, "cksum: %s: %s\n",
110 fn ? fn : "stdin", strerror(errno));
110 warn("%s", fn ? fn : "stdin");
111 rval = 1;
112 } else
113 pfncn(fn, val, len);
114 (void)close(fd);
115 } while (*argv);
116 exit(rval);
117}
118
111 rval = 1;
112 } else
113 pfncn(fn, val, len);
114 (void)close(fd);
115 } while (*argv);
116 exit(rval);
117}
118
119void
119static void
120usage()
121{
122 (void)fprintf(stderr, "usage: cksum [-o 1 | 2] [file ...]\n");
123 exit(1);
124}
120usage()
121{
122 (void)fprintf(stderr, "usage: cksum [-o 1 | 2] [file ...]\n");
123 exit(1);
124}