Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : CALCCRC.C

 
Output of file : CALCCRC.C contained in archive : STLTH22.ZIP
/*
calccrc.c
Stealth Bomber Version 2.2

Kevin Dean
Fairview Mall P.O. Box 55074
1800 Sheppard Avenue East
Willowdale, Ontario
CANADA M2J 5B9
CompuServe ID: 76336,3114

February 10, 1992

This module calculates the CRC of a file.

This code is public domain.
*/


#include

#include "vircheck.h"


/* Macros to extract low and high bytes of a word. */
#define lowb(x) (*(unsigned char *)&(x))
#define hib(x) (*((unsigned char *)&(x) + 1))

/* Macros to extract low and high words of a dword. */
#define loww(x) (*(unsigned short *)&(x))
#define hiw(x) (*((unsigned short *)&(x) + 1))


/***/
/* Calculate the CRC of a file. The file is assumed to be open and the buffer is assumed to be valid. */
crc32_t calccrc(FILE *f, byte *buffer, size_t bufsize, crc32_t polynomial)
{
crc32_t table[256]; /* CRC table. */
register size_t i; /* Byte counter. */
register crc32_t *halfi; /* Pointer to CRC of i / 2. */
crc32_t crc; /* Current CRC. */
byte *bufptr; /* Pointer to walk through buffer. */

/* Generate a CRC lookup table for faster calculation. */
for (i = 0, halfi = table, table[0] = 0; i < 256; i += 2, halfi++)
if (hib(hiw(*halfi)) & 0x80)
table[i] = (table[i + 1] = *halfi << 1) ^ polynomial;
else
table[i + 1] = (table[i] = *halfi << 1) ^ polynomial;

/* Calculate CRC. */
crc = 0;
while ((i = fread(buffer, 1, bufsize, f)) != 0)
for (bufptr = buffer; i--; bufptr++)
crc = (crc << 8) ^ table[hib(hiw(crc)) ^ *bufptr];

return (crc);
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : CALCCRC.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/