crc.c (9b50d9027575220cb6dd09b3e62f03f511e908b8) crc.c (4933ffaed9927902d8e810b6989996c0e1221321)
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

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

36
37#ifndef lint
38static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
39#endif /* not lint */
40
41#include <sys/types.h>
42#include <unistd.h>
43
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

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

36
37#ifndef lint
38static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
39#endif /* not lint */
40
41#include <sys/types.h>
42#include <unistd.h>
43
44static u_long crctab[] = {
44static const u_int32_t crctab[] = {
45 0x0,
46 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
47 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
48 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
49 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
50 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
51 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
52 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,

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

97};
98
99/*
100 * Compute a POSIX 1003.2 checksum. This routine has been broken out so that
101 * other programs can use it. It takes a file descriptor to read from and
102 * locations to store the crc and the number of bytes read. It returns 0 on
103 * success and 1 on failure. Errno is set on failure.
104 */
45 0x0,
46 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
47 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
48 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
49 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
50 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
51 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
52 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,

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

97};
98
99/*
100 * Compute a POSIX 1003.2 checksum. This routine has been broken out so that
101 * other programs can use it. It takes a file descriptor to read from and
102 * locations to store the crc and the number of bytes read. It returns 0 on
103 * success and 1 on failure. Errno is set on failure.
104 */
105u_long crc_total = ~0; /* The crc over a number of files. */
105u_int32_t crc_total = ~0; /* The crc over a number of files. */
106
107int
108crc(fd, cval, clen)
109 register int fd;
106
107int
108crc(fd, cval, clen)
109 register int fd;
110 u_long *cval, *clen;
110 u_int32_t *cval, *clen;
111{
112 register u_char *p;
113 register int nr;
111{
112 register u_char *p;
113 register int nr;
114 register u_long crc, len;
114 register u_int32_t crc, len;
115 u_char buf[16 * 1024];
116
117#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
118
119 crc = len = 0;
120 crc_total = ~crc_total;
121 while ((nr = read(fd, buf, sizeof(buf))) > 0)
122 for (len += nr, p = buf; nr--; ++p) {

--- 18 unchanged lines hidden ---
115 u_char buf[16 * 1024];
116
117#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
118
119 crc = len = 0;
120 crc_total = ~crc_total;
121 while ((nr = read(fd, buf, sizeof(buf))) > 0)
122 for (len += nr, p = buf; nr--; ++p) {

--- 18 unchanged lines hidden ---