]> granicus.if.org Git - postgresql/blob - contrib/ltree/crc32.c
Move pg_crc.c to src/common, and remove pg_crc_tables.h
[postgresql] / contrib / ltree / crc32.c
1 /* contrib/ltree/crc32.c */
2
3 /*
4  * Implements CRC-32, as used in ltree.
5  *
6  * Note that the CRC is used in the on-disk format of GiST indexes, so we
7  * must stay backwards-compatible!
8  */
9
10 #include "postgres.h"
11
12 #include <sys/types.h>
13 #include <stdio.h>
14 #include <sys/types.h>
15
16 #ifdef LOWER_NODE
17 #include <ctype.h>
18 #define TOLOWER(x)      tolower((unsigned char) (x))
19 #else
20 #define TOLOWER(x)      (x)
21 #endif
22
23 #include "common/pg_crc.h"
24 #include "crc32.h"
25
26 unsigned int
27 ltree_crc32_sz(char *buf, int size)
28 {
29         pg_crc32 crc;
30         char       *p = buf;
31
32         INIT_TRADITIONAL_CRC32(crc);
33         while (size > 0)
34         {
35                 char c = (char) TOLOWER(*p);
36                 COMP_TRADITIONAL_CRC32(crc, &c, 1);
37                 size--;
38                 p++;
39         }
40         FIN_TRADITIONAL_CRC32(crc);
41         return (unsigned int) crc;
42 }