PostgreSQL Source Code git master
pgtypeslib_extern.h File Reference
#include "pgtypes_error.h"
Include dependency graph for pgtypeslib_extern.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  un_fmt_comb
 

Macros

#define PGTYPES_TYPE_NOTHING   0
 
#define PGTYPES_TYPE_STRING_MALLOCED   1
 
#define PGTYPES_TYPE_STRING_CONSTANT   2
 
#define PGTYPES_TYPE_CHAR   3
 
#define PGTYPES_TYPE_DOUBLE_NF   4 /* no fractional part */
 
#define PGTYPES_TYPE_INT64   5
 
#define PGTYPES_TYPE_UINT   6
 
#define PGTYPES_TYPE_UINT_2_LZ   7 /* 2 digits, pad with leading zero */
 
#define PGTYPES_TYPE_UINT_2_LS
 
#define PGTYPES_TYPE_UINT_3_LZ   9
 
#define PGTYPES_TYPE_UINT_4_LZ   10
 
#define PGTYPES_TYPE_UINT_LONG   11
 
#define PGTYPES_FMT_NUM_MAX_DIGITS   40
 

Functions

int pgtypes_fmt_replace (union un_fmt_comb replace_val, int replace_type, char **output, int *pstr_len)
 
char * pgtypes_alloc (long size)
 
char * pgtypes_strdup (const char *str)
 

Macro Definition Documentation

◆ PGTYPES_FMT_NUM_MAX_DIGITS

#define PGTYPES_FMT_NUM_MAX_DIGITS   40

Definition at line 23 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_CHAR

#define PGTYPES_TYPE_CHAR   3

Definition at line 13 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_DOUBLE_NF

#define PGTYPES_TYPE_DOUBLE_NF   4 /* no fractional part */

Definition at line 14 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_INT64

#define PGTYPES_TYPE_INT64   5

Definition at line 15 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_NOTHING

#define PGTYPES_TYPE_NOTHING   0

Definition at line 10 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_STRING_CONSTANT

#define PGTYPES_TYPE_STRING_CONSTANT   2

Definition at line 12 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_STRING_MALLOCED

#define PGTYPES_TYPE_STRING_MALLOCED   1

Definition at line 11 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT

#define PGTYPES_TYPE_UINT   6

Definition at line 16 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT_2_LS

#define PGTYPES_TYPE_UINT_2_LS
Value:
8 /* 2 digits, pad with leading
* space */

Definition at line 18 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT_2_LZ

#define PGTYPES_TYPE_UINT_2_LZ   7 /* 2 digits, pad with leading zero */

Definition at line 17 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT_3_LZ

#define PGTYPES_TYPE_UINT_3_LZ   9

Definition at line 19 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT_4_LZ

#define PGTYPES_TYPE_UINT_4_LZ   10

Definition at line 20 of file pgtypeslib_extern.h.

◆ PGTYPES_TYPE_UINT_LONG

#define PGTYPES_TYPE_UINT_LONG   11

Definition at line 21 of file pgtypeslib_extern.h.

Function Documentation

◆ pgtypes_alloc()

char * pgtypes_alloc ( long  size)

Definition at line 10 of file common.c.

11{
12 char *new = (char *) calloc(1L, size);
13
14 if (!new)
15 errno = ENOMEM;
16 return new;
17}
#define calloc(a, b)
Definition: header.h:55
static pg_noinline void Size size
Definition: slab.c:607

References calloc, and size.

Referenced by get_str_from_var(), pgtypes_fmt_replace(), PGTYPESdate_defmt_asc(), PGTYPESdate_fmt_asc(), PGTYPESdate_new(), PGTYPESdecimal_new(), PGTYPESinterval_from_asc(), PGTYPESinterval_new(), PGTYPESnumeric_from_asc(), PGTYPESnumeric_new(), and PGTYPEStimestamp_defmt_scan().

◆ pgtypes_fmt_replace()

int pgtypes_fmt_replace ( union un_fmt_comb  replace_val,
int  replace_type,
char **  output,
int *  pstr_len 
)

Definition at line 30 of file common.c.

31{
32 /*
33 * general purpose variable, set to 0 in order to fix compiler warning
34 */
35 int i = 0;
36
37 switch (replace_type)
38 {
40 break;
43 i = strlen(replace_val.str_val);
44 if (i + 1 <= *pstr_len)
45 {
46 /* include trailing terminator in what we copy */
47 memcpy(*output, replace_val.str_val, i + 1);
48 *pstr_len -= i;
49 *output += i;
50 if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)
51 free(replace_val.str_val);
52 return 0;
53 }
54 else
55 return -1;
56 break;
58 if (*pstr_len >= 2)
59 {
60 (*output)[0] = replace_val.char_val;
61 (*output)[1] = '\0';
62 (*pstr_len)--;
63 (*output)++;
64 return 0;
65 }
66 else
67 return -1;
68 break;
76 {
78
79 if (!t)
80 return ENOMEM;
81 switch (replace_type)
82 {
85 "%0.0g", replace_val.double_val);
86 break;
89 INT64_FORMAT, replace_val.int64_val);
90 break;
93 "%u", replace_val.uint_val);
94 break;
97 "%02u", replace_val.uint_val);
98 break;
101 "%2u", replace_val.uint_val);
102 break;
105 "%03u", replace_val.uint_val);
106 break;
109 "%04u", replace_val.uint_val);
110 break;
111 }
112
113 if (i < 0 || i >= PGTYPES_FMT_NUM_MAX_DIGITS)
114 {
115 free(t);
116 return -1;
117 }
118 i = strlen(t);
119 *pstr_len -= i;
120
121 /*
122 * if *pstr_len == 0, we don't have enough space for the
123 * terminator and the conversion fails
124 */
125 if (*pstr_len <= 0)
126 {
127 free(t);
128 return -1;
129 }
130 strcpy(*output, t);
131 *output += i;
132 free(t);
133 }
134 break;
135 default:
136 break;
137 }
138 return 0;
139}
#define INT64_FORMAT
Definition: c.h:506
#define free(a)
Definition: header.h:65
FILE * output
char * pgtypes_alloc(long size)
Definition: common.c:10
int i
Definition: isn.c:72
#define PGTYPES_TYPE_STRING_CONSTANT
#define PGTYPES_TYPE_NOTHING
#define PGTYPES_TYPE_DOUBLE_NF
#define PGTYPES_TYPE_UINT
#define PGTYPES_TYPE_CHAR
#define PGTYPES_TYPE_STRING_MALLOCED
#define PGTYPES_FMT_NUM_MAX_DIGITS
#define PGTYPES_TYPE_UINT_2_LS
#define PGTYPES_TYPE_UINT_4_LZ
#define PGTYPES_TYPE_UINT_2_LZ
#define PGTYPES_TYPE_INT64
#define PGTYPES_TYPE_UINT_3_LZ
#define snprintf
Definition: port.h:238
unsigned int uint_val

References un_fmt_comb::char_val, un_fmt_comb::double_val, free, i, INT64_FORMAT, un_fmt_comb::int64_val, output, pgtypes_alloc(), PGTYPES_FMT_NUM_MAX_DIGITS, PGTYPES_TYPE_CHAR, PGTYPES_TYPE_DOUBLE_NF, PGTYPES_TYPE_INT64, PGTYPES_TYPE_NOTHING, PGTYPES_TYPE_STRING_CONSTANT, PGTYPES_TYPE_STRING_MALLOCED, PGTYPES_TYPE_UINT, PGTYPES_TYPE_UINT_2_LS, PGTYPES_TYPE_UINT_2_LZ, PGTYPES_TYPE_UINT_3_LZ, PGTYPES_TYPE_UINT_4_LZ, snprintf, un_fmt_comb::str_val, and un_fmt_comb::uint_val.

Referenced by dttofmtasc_replace().

◆ pgtypes_strdup()

char * pgtypes_strdup ( const char *  str)

Definition at line 20 of file common.c.

21{
22 char *new = (char *) strdup(str);
23
24 if (!new)
25 errno = ENOMEM;
26 return new;
27}
const char * str

References str.

Referenced by pgtypes_defmt_scan(), PGTYPESdate_defmt_asc(), PGTYPESdate_to_asc(), PGTYPESinterval_to_asc(), PGTYPEStimestamp_defmt_asc(), and PGTYPEStimestamp_to_asc().