aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/bool.c
blob: cb9163f020fe390dc2992c2dd76117e2c72af98e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*-------------------------------------------------------------------------
 *
 * bool.c--
 *    Functions for the built-in type "bool".
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *    $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.4 1997/04/27 19:20:07 thomas Exp $
 *
 *-------------------------------------------------------------------------
 */

#include "postgres.h"

#include "utils/builtins.h"	/* where the declarations go */
#include "utils/palloc.h"

/***************************************************************************** 
 *   USER I/O ROUTINES                                                       *
 *****************************************************************************/

/*
 *	boolin		- converts "t" or "f" to 1 or 0
 */
bool
boolin(char *b)
{
    if (b == NULL)
	elog(WARN, "Bad input string for type bool");
    return((bool) (*b == 't') || (*b == 'T'));
}

/*
 *	boolout		- converts 1 or 0 to "t" or "f"
 */
char *
boolout(long b)
{
    char	*result = (char *) palloc(2);
    
    *result = (b) ? 't' : 'f';
    result[1] = '\0';
    return(result);
}

/***************************************************************************** 
 *   PUBLIC ROUTINES                                                         *
 *****************************************************************************/

bool
booleq(int8 arg1, int8 arg2)	
{ 
    return(arg1 == arg2); 
}

bool
boolne(int8 arg1, int8 arg2)	
{
    return(arg1 != arg2); 
}

bool
boollt(int8 arg1, int8 arg2)	
{ 
    return(arg1 < arg2); 
}

bool
boolgt(int8 arg1, int8 arg2)	
{ 
    return(arg1 > arg2); 
}