- For variables holding offset values, use off_t rather than

int, long int or u_int32_t.  This changes the interface of
   all the CRC calculation and output functions from cksum.
 - Print variables of type off_t as intmax_t using a cast and %jd.
 - Use the standardized uint32_t type instead of u_int32_t.
   To have uint32_t defined, include <stdint.h> where necessary.
Style(9):
 - Move #include directives where they belong (esp. crc32.c).
 - Add empty lines between #include directives of system headers,
   standard library headers and local headers.
 - Test a pointer value against NULL.
 - Put a space after the return keyword.

PR:		bin/48424
This commit is contained in:
Robert Drehmel 2003-03-13 23:32:28 +00:00
parent 13917c99d1
commit 60b588eb94
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=112212
7 changed files with 57 additions and 41 deletions

View File

@ -45,6 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)cksum.c 8.2 (Berkeley) 4/28/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -64,11 +65,12 @@ static void usage(void);
int
main(int argc, char **argv)
{
uint32_t val;
int ch, fd, rval;
u_int32_t len, val;
off_t len;
char *fn, *p;
int (*cfncn)(int, u_int32_t *, u_int32_t *);
void (*pfncn)(char *, u_int32_t, u_int32_t);
int (*cfncn)(int, uint32_t *, off_t *);
void (*pfncn)(char *, u_int32_t, off_t);
if ((p = rindex(argv[0], '/')) == NULL)
p = argv[0];

View File

@ -43,11 +43,13 @@ static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <stdint.h>
#include <unistd.h>
#include "extern.h"
static const u_int32_t crctab[] = {
static const uint32_t crctab[] = {
0x0,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
@ -108,14 +110,15 @@ static const u_int32_t crctab[] = {
* locations to store the crc and the number of bytes read. It returns 0 on
* success and 1 on failure. Errno is set on failure.
*/
u_int32_t crc_total = ~0; /* The crc over a number of files. */
uint32_t crc_total = ~0; /* The crc over a number of files. */
int
crc(int fd, u_int32_t *cval, u_int32_t *clen)
crc(int fd, uint32_t *cval, off_t *clen)
{
u_char *p;
uint32_t lcrc;
int nr;
u_int32_t lcrc, len;
off_t len;
u_char *p;
u_char buf[16 * 1024];
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]

View File

@ -16,6 +16,10 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "extern.h"
#define CRC(crc, ch) (crc = (crc >> 8) ^ crctab[(crc ^ (ch)) & 0xff])
@ -24,7 +28,7 @@ __FBSDID("$FreeBSD$");
* x^32 + x^26 + x^23 + x^22 + x^16 +
* x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1
*/
static const u_int32_t crctab[256] = {
static const uint32_t crctab[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@ -91,18 +95,15 @@ static const u_int32_t crctab[256] = {
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
u_int32_t crc32_total = 0 ;
uint32_t crc32_total = 0;
int
crc32(int fd, u_int32_t *cval, u_int32_t *clen)
crc32(int fd, uint32_t *cval, off_t *clen)
{
u_int32_t lcrc = ~0;
uint32_t lcrc = ~0;
int nr ;
off_t len ;
char buf[BUFSIZ], *p ;
int len, nr ;
len = 0 ;
crc32_total = ~crc32_total ;

View File

@ -37,11 +37,11 @@
#include <sys/cdefs.h>
__BEGIN_DECLS
int crc(int, u_int32_t *, u_int32_t *);
void pcrc(char *, u_int32_t, u_int32_t);
void psum1(char *, u_int32_t, u_int32_t);
void psum2(char *, u_int32_t, u_int32_t);
int csum1(int, u_int32_t *, u_int32_t *);
int csum2(int, u_int32_t *, u_int32_t *);
int crc32(int, u_int32_t *, u_int32_t *);
int crc(int, uint32_t *, off_t *);
void pcrc(char *, uint32_t, off_t);
void psum1(char *, uint32_t, off_t);
void psum2(char *, uint32_t, off_t);
int csum1(int, uint32_t *, off_t *);
int csum2(int, uint32_t *, off_t *);
int crc32(int, uint32_t *, off_t *);
__END_DECLS

View File

@ -36,36 +36,40 @@
static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include "extern.h"
void
pcrc(char *fn, u_int32_t val, u_int32_t len)
pcrc(char *fn, uint32_t val, off_t len)
{
(void)printf("%lu %lu", (u_long) val, (u_long) len);
if (fn)
(void)printf("%lu %jd", (u_long)val, (intmax_t)len);
if (fn != NULL)
(void)printf(" %s", fn);
(void)printf("\n");
}
void
psum1(char *fn, u_int32_t val, u_int32_t len)
psum1(char *fn, uint32_t val, off_t len)
{
(void)printf("%lu %lu", (u_long) val, (u_long) (len + 1023) / 1024);
if (fn)
(void)printf("%lu %jd", (u_long)val, (intmax_t)(len + 1023) / 1024);
if (fn != NULL)
(void)printf(" %s", fn);
(void)printf("\n");
}
void
psum2(char *fn, u_int32_t val, u_int32_t len)
psum2(char *fn, uint32_t val, off_t len)
{
(void)printf("%lu %lu", (u_long) val, (u_long) (len + 511) / 512);
if (fn)
(void)printf("%lu %jd", (u_long)val, (intmax_t)(len + 511) / 512);
if (fn != NULL)
(void)printf(" %s", fn);
(void)printf("\n");
}

View File

@ -36,20 +36,23 @@
static char sccsid[] = "@(#)sum1.c 8.1 (Berkeley) 6/6/93";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include "extern.h"
int
csum1(int fd, u_int32_t *cval, u_int32_t *clen)
csum1(int fd, uint32_t *cval, off_t *clen)
{
u_int32_t total;
int nr;
u_int lcrc;
off_t total;
u_char *p;
u_char buf[8192];
@ -65,9 +68,9 @@ csum1(int fd, u_int32_t *cval, u_int32_t *clen)
lcrc = ((lcrc >> 1) + *p) & 0xffff;
}
if (nr < 0)
return(1);
return (1);
*cval = lcrc;
*clen = total;
return(0);
return (0);
}

View File

@ -40,15 +40,18 @@ static char sccsid[] = "@(#)sum2.c 8.1 (Berkeley) 6/6/93";
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include "extern.h"
int
csum2(int fd, u_int32_t *cval, u_int32_t *clen)
csum2(int fd, uint32_t *cval, off_t *clen)
{
u_int32_t lcrc, total;
uint32_t lcrc;
int nr;
off_t total;
u_char *p;
u_char buf[8192];
@ -64,12 +67,12 @@ csum2(int fd, u_int32_t *cval, u_int32_t *clen)
for (total += nr, p = buf; nr--; ++p)
lcrc += *p;
if (nr < 0)
return(1);
return (1);
lcrc = (lcrc & 0xffff) + (lcrc >> 16);
lcrc = (lcrc & 0xffff) + (lcrc >> 16);
*cval = lcrc;
*clen = total;
return(0);
return (0);
}