#include "postgres.h"

char *charNN_in(char *cstr);
char *charNN_out(char *sstr);
bool charNN_lt(char *a, char *b);
bool charNN_le(char *a, char *b);
bool charNN_eq(char *a, char *b);
bool charNN_ge(char *a, char *b);
bool charNN_gt(char *a, char *b);
bool charNN_ne(char *a, char *b);
int4 charNN_cmp(char *a, char *b);

char *
charNN_in(char *cstr)
{
	char *result;
	int len;
	int i;

	len = strlen(cstr);
	if (len > NN)
		len = NN;

	result = (char *) palloc(NN);
	for (i = 0; i < len; ++i)
		result[i] = cstr[i];

	for (; i < NN; ++i)
		result[i] = ' ';

	return result;
}/*charNN_in*/

char *
charNN_out(char *sstr)
{
	char *result;
	int i;

	if (sstr == NULL)
		return NULL;

	result = (char *) palloc(NN + 1);
	for (i = 0; i < NN; ++i)
		result[i] = sstr[i];

	result[NN] = '\0';

	return result;
}/*charNN_out*/

bool
charNN_lt(char *a, char *b)
{
	return (strncmp(a, b, NN) < 0);
}/*charNN_lt*/

bool
charNN_le(char *a, char *b)
{
	return (strncmp(a, b, NN) <= 0);
}/*charNN_le*/

bool
charNN_eq(char *a, char *b)
{
	return (strncmp(a, b, NN) == 0);
}/*charNN_eq*/

bool
charNN_ge(char *a, char *b)
{
	return (strncmp(a, b, NN) >= 0);
}/*charNN_ge*/

bool
charNN_gt(char *a, char *b)
{
	return (strncmp(a, b, NN) > 0);
}/*charNN_gt*/

bool
charNN_ne(char *a, char *b)
{
	return (strncmp(a, b, NN) != 0);
}/*charNN_ne*/

int4
charNN_cmp(char *a, char *b)
{
	return strncmp(a, b, NN);
}/*charNN_cmp*/
