X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/0875b58fcccadd756e11487185c2ac1d3ed8ab4d..573eadb534c42c4feace5e493cc135dd5e7b00d9:/crc32.h diff --git a/crc32.h b/crc32.h index 5d4b2fa..2b36e5f 100644 --- a/crc32.h +++ b/crc32.h @@ -1,56 +1,78 @@ /* -*-c-*- * - * $Id: crc32.h,v 1.1 1998/06/17 23:44:42 mdw Exp $ + * $Id: crc32.h,v 1.6 2000/07/02 22:20:42 mdw Exp $ * * Calculating cyclic redundancy values (non-cryptographic!) * * (c) 1998 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * * mLib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with mLib; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with mLib; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. */ /*----- Revision history --------------------------------------------------* * * $Log: crc32.h,v $ - * Revision 1.1 1998/06/17 23:44:42 mdw - * Initial revision + * Revision 1.6 2000/07/02 22:20:42 mdw + * Fix constant name. + * + * Revision 1.5 1999/12/10 23:42:04 mdw + * Change header file guard names. + * + * Revision 1.4 1999/06/01 09:47:22 mdw + * Make the return type of `crc32' a `uint32' now that we have `bits.h'. + * + * Revision 1.3 1999/05/06 19:51:35 mdw + * Reformatted the LGPL notice a little bit. + * + * Revision 1.2 1999/05/05 18:50:31 mdw + * Change licensing conditions to LGPL. + * + * Revision 1.1.1.1 1998/06/17 23:44:42 mdw + * Initial version of mLib * */ -#ifndef CRC32_H -#define CRC32_h +#ifndef MLIB_CRC32_H +#define MLIB_CRC32_H #ifdef __cplusplus extern "C" { #endif +/*----- Header files ------------------------------------------------------*/ + +#ifndef MLIB_BITS_H +# include "bits.h" +#endif + /*----- External values ---------------------------------------------------*/ -extern unsigned long crc32_table[256]; +extern uint32 crc32_table[256]; /*----- Macros ------------------------------------------------------------*/ /* --- @CRC32@ --- * * - * Arguments: @unsigned long result@ = where to put the result - * @unsigned long crc@ = carryover from previous call, or zero + * Arguments: @uint32 result@ = where to put the result + * @uint32 crc@ = carryover from previous call, or zero * @void *buf@ = pointer to buffer to check * @size_t sz@ = size of the buffer * @@ -58,20 +80,20 @@ extern unsigned long crc32_table[256]; */ #define CRC32(result, crc, buf, sz) do { \ - const unsigned char *_p = (const unsigned char *)(buf); \ - const unsigned char *_l = _p + (sz); \ - unsigned long _crc = ~(crc) & 0xffffffffu; \ + const octet *_p = (const octet *)(buf); \ + const octet *_l = _p + (sz); \ + uint32 _crc = U32(~(crc)); \ \ while (_p < _l) \ - _crc = (_crc >> 8) ^ crc32_table[(*_p++ ^ _crc) & 0xffu]; \ - (result) = ~_crc & 0xffffffffu; \ + _crc = (_crc >> 8) ^ crc32_table[U8(*_p++ ^ _crc)]; \ + (result) = U32(~_crc); \ } while (0) /*----- Functions provided ------------------------------------------------*/ /* --- @crc32@ --- * * - * Arguments: @unsigned long crc@ = carryover from previous call, or zero + * Arguments: @uint32 crc@ = carryover from previous call, or zero * @const void *buf@ = pointer to buffer to check * @size_t sz@ = size of the buffer * @@ -81,8 +103,7 @@ extern unsigned long crc32_table[256]; * wrapper for the macro version. */ -extern unsigned long crc32(unsigned long /*crc*/, - const void */*buf*/, size_t /*sz*/); +extern uint32 crc32(uint32 /*crc*/, const void */*buf*/, size_t /*sz*/); /*----- That's all, folks -------------------------------------------------*/