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 "utils/pg_crc.h"
24 #include "crc32.h"
25 
26 unsigned int
ltree_crc32_sz(char * buf,int size)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 
37 		COMP_TRADITIONAL_CRC32(crc, &c, 1);
38 		size--;
39 		p++;
40 	}
41 	FIN_TRADITIONAL_CRC32(crc);
42 	return (unsigned int) crc;
43 }
44