postgresql/contrib/ltree/crc32.c
Heikki Linnakangas c619c2351f Move pg_crc.c to src/common, and remove pg_crc_tables.h
To get CRC functionality in a client program, you now need to link with
libpgcommon instead of libpgport. The CRC code has nothing to do with
portability, so libpgcommon is a better home. (libpgcommon didn't exist
when pg_crc.c was originally moved to src/port.)

Remove the possibility to get CRC functionality by just #including
pg_crc_tables.h. I'm not aware of any extensions that actually did that and
couldn't simply link with libpgcommon.

This also moves the pg_crc.h header file from src/include/utils to
src/include/common, which will require changes to any external programs
that currently does #include "utils/pg_crc.h". That seems acceptable, as
include/common is clearly the right home for it now, and the change needed
to any such programs is trivial.
2015-02-09 11:17:56 +02:00

43 lines
732 B
C

/* contrib/ltree/crc32.c */
/*
* Implements CRC-32, as used in ltree.
*
* Note that the CRC is used in the on-disk format of GiST indexes, so we
* must stay backwards-compatible!
*/
#include "postgres.h"
#include <sys/types.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef LOWER_NODE
#include <ctype.h>
#define TOLOWER(x) tolower((unsigned char) (x))
#else
#define TOLOWER(x) (x)
#endif
#include "common/pg_crc.h"
#include "crc32.h"
unsigned int
ltree_crc32_sz(char *buf, int size)
{
pg_crc32 crc;
char *p = buf;
INIT_TRADITIONAL_CRC32(crc);
while (size > 0)
{
char c = (char) TOLOWER(*p);
COMP_TRADITIONAL_CRC32(crc, &c, 1);
size--;
p++;
}
FIN_TRADITIONAL_CRC32(crc);
return (unsigned int) crc;
}