]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sbin/hastd/crc32.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sbin / hastd / crc32.h
1 /*-
2  *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
3  *  code or tables extracted from it, as desired without restriction.
4  *
5  * $FreeBSD$
6  */
7
8 #ifndef _CRC32_H_
9 #define _CRC32_H_
10
11 #include <stdint.h>     /* uint32_t */
12 #include <stdlib.h>     /* size_t */
13
14 extern uint32_t crc32_tab[];
15
16 static __inline uint32_t
17 crc32(const void *buf, size_t size)
18 {
19         const uint8_t *p = buf;
20         uint32_t crc;
21
22         crc = ~0U;
23         while (size--)
24                 crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
25         return (crc ^ ~0U);
26 }
27
28 #endif  /* !_CRC32_H_ */