1 /*-------------------------------------------------------------------------
2  *
3  * builtins.h
4  *	  Declarations for operations on built-in types.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/utils/builtins.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef BUILTINS_H
15 #define BUILTINS_H
16 
17 #include "fmgr.h"
18 #include "nodes/nodes.h"
19 #include "utils/fmgrprotos.h"
20 
21 /* Sign + the most decimal digits an 8-byte number could have */
22 #define MAXINT8LEN 20
23 
24 /* bool.c */
25 extern bool parse_bool(const char *value, bool *result);
26 extern bool parse_bool_with_len(const char *value, size_t len, bool *result);
27 
28 /* domains.c */
29 extern void domain_check(Datum value, bool isnull, Oid domainType,
30 						 void **extra, MemoryContext mcxt);
31 extern int	errdatatype(Oid datatypeOid);
32 extern int	errdomainconstraint(Oid datatypeOid, const char *conname);
33 
34 /* encode.c */
35 extern uint64 hex_encode(const char *src, size_t len, char *dst);
36 extern uint64 hex_decode(const char *src, size_t len, char *dst);
37 
38 /* int.c */
39 extern int2vector *buildint2vector(const int16 *int2s, int n);
40 
41 /* name.c */
42 extern void namestrcpy(Name name, const char *str);
43 extern int	namestrcmp(Name name, const char *str);
44 
45 /* numutils.c */
46 extern int32 pg_atoi(const char *s, int size, int c);
47 extern int16 pg_strtoint16(const char *s);
48 extern int32 pg_strtoint32(const char *s);
49 extern int	pg_itoa(int16 i, char *a);
50 extern int	pg_ultoa_n(uint32 l, char *a);
51 extern int	pg_ulltoa_n(uint64 l, char *a);
52 extern int	pg_ltoa(int32 l, char *a);
53 extern int	pg_lltoa(int64 ll, char *a);
54 extern char *pg_ultostr_zeropad(char *str, uint32 value, int32 minwidth);
55 extern char *pg_ultostr(char *str, uint32 value);
56 extern uint64 pg_strtouint64(const char *str, char **endptr, int base);
57 
58 /* oid.c */
59 extern oidvector *buildoidvector(const Oid *oids, int n);
60 extern Oid	oidparse(Node *node);
61 extern int	oid_cmp(const void *p1, const void *p2);
62 
63 /* regexp.c */
64 extern char *regexp_fixed_prefix(text *text_re, bool case_insensitive,
65 								 Oid collation, bool *exact);
66 
67 /* ruleutils.c */
68 extern bool quote_all_identifiers;
69 extern const char *quote_identifier(const char *ident);
70 extern char *quote_qualified_identifier(const char *qualifier,
71 										const char *ident);
72 extern void generate_operator_clause(fmStringInfo buf,
73 									 const char *leftop, Oid leftoptype,
74 									 Oid opoid,
75 									 const char *rightop, Oid rightoptype);
76 
77 /* varchar.c */
78 extern int	bpchartruelen(char *s, int len);
79 
80 /* popular functions from varlena.c */
81 extern text *cstring_to_text(const char *s);
82 extern text *cstring_to_text_with_len(const char *s, int len);
83 extern char *text_to_cstring(const text *t);
84 extern void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len);
85 
86 #define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
87 #define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))
88 
89 /* xid.c */
90 extern int	xidComparator(const void *arg1, const void *arg2);
91 
92 /* inet_cidr_ntop.c */
93 extern char *pg_inet_cidr_ntop(int af, const void *src, int bits,
94 							   char *dst, size_t size);
95 
96 /* inet_net_pton.c */
97 extern int	pg_inet_net_pton(int af, const char *src,
98 							 void *dst, size_t size);
99 
100 /* network.c */
101 extern double convert_network_to_scalar(Datum value, Oid typid, bool *failure);
102 extern Datum network_scan_first(Datum in);
103 extern Datum network_scan_last(Datum in);
104 extern void clean_ipv6_addr(int addr_family, char *addr);
105 
106 /* numeric.c */
107 extern Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS);
108 
109 /* format_type.c */
110 
111 /* Control flags for format_type_extended */
112 #define FORMAT_TYPE_TYPEMOD_GIVEN	0x01	/* typemod defined by caller */
113 #define FORMAT_TYPE_ALLOW_INVALID	0x02	/* allow invalid types */
114 #define FORMAT_TYPE_FORCE_QUALIFY	0x04	/* force qualification of type */
115 #define FORMAT_TYPE_INVALID_AS_NULL	0x08	/* NULL if undefined */
116 extern char *format_type_extended(Oid type_oid, int32 typemod, bits16 flags);
117 
118 extern char *format_type_be(Oid type_oid);
119 extern char *format_type_be_qualified(Oid type_oid);
120 extern char *format_type_with_typemod(Oid type_oid, int32 typemod);
121 
122 extern int32 type_maximum_size(Oid type_oid, int32 typemod);
123 
124 /* quote.c */
125 extern char *quote_literal_cstr(const char *rawstr);
126 
127 #endif							/* BUILTINS_H */
128