PostgreSQL Source Code  git master
extern.h File Reference
#include "pgtypes_error.h"
Include dependency graph for 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
 
#define bool   char
 
#define FALSE   0
 
#define TRUE   1
 

Functions

int pgtypes_fmt_replace (union un_fmt_comb, int, char **, int *)
 
char * pgtypes_alloc (long)
 
char * pgtypes_strdup (const char *)
 

Macro Definition Documentation

◆ bool

#define bool   char

Definition at line 42 of file extern.h.

◆ FALSE

#define FALSE   0

Definition at line 46 of file extern.h.

◆ PGTYPES_FMT_NUM_MAX_DIGITS

#define PGTYPES_FMT_NUM_MAX_DIGITS   40

Definition at line 24 of file extern.h.

Referenced by pgtypes_fmt_replace().

◆ PGTYPES_TYPE_CHAR

#define PGTYPES_TYPE_CHAR   3

Definition at line 13 of file extern.h.

Referenced by dttofmtasc_replace(), and pgtypes_fmt_replace().

◆ PGTYPES_TYPE_DOUBLE_NF

#define PGTYPES_TYPE_DOUBLE_NF   4 /* no fractional part */

Definition at line 14 of file extern.h.

Referenced by pgtypes_fmt_replace().

◆ PGTYPES_TYPE_INT64

#define PGTYPES_TYPE_INT64   5

Definition at line 15 of file extern.h.

Referenced by dttofmtasc_replace(), and pgtypes_fmt_replace().

◆ PGTYPES_TYPE_NOTHING

#define PGTYPES_TYPE_NOTHING   0

Definition at line 10 of file extern.h.

Referenced by dttofmtasc_replace(), and pgtypes_fmt_replace().

◆ PGTYPES_TYPE_STRING_CONSTANT

#define PGTYPES_TYPE_STRING_CONSTANT   2

Definition at line 12 of file extern.h.

Referenced by dttofmtasc_replace(), pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

◆ PGTYPES_TYPE_STRING_MALLOCED

#define PGTYPES_TYPE_STRING_MALLOCED   1

◆ PGTYPES_TYPE_UINT

#define PGTYPES_TYPE_UINT   6

◆ 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 extern.h.

Referenced by dttofmtasc_replace(), and pgtypes_fmt_replace().

◆ PGTYPES_TYPE_UINT_2_LZ

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

Definition at line 17 of file extern.h.

Referenced by dttofmtasc_replace(), pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

◆ PGTYPES_TYPE_UINT_3_LZ

#define PGTYPES_TYPE_UINT_3_LZ   9

Definition at line 20 of file extern.h.

Referenced by dttofmtasc_replace(), and pgtypes_fmt_replace().

◆ PGTYPES_TYPE_UINT_4_LZ

#define PGTYPES_TYPE_UINT_4_LZ   10

Definition at line 21 of file extern.h.

Referenced by pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

◆ PGTYPES_TYPE_UINT_LONG

#define PGTYPES_TYPE_UINT_LONG   11

Definition at line 22 of file extern.h.

Referenced by pgtypes_defmt_scan(), and PGTYPEStimestamp_defmt_scan().

◆ TRUE

#define TRUE   1

Definition at line 50 of file extern.h.

Function Documentation

◆ pgtypes_alloc()

char* pgtypes_alloc ( long  )

Definition at line 9 of file common.c.

References calloc.

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().

10 {
11  char *new = (char *) calloc(1L, size);
12 
13  if (!new)
14  errno = ENOMEM;
15  return new;
16 }
#define calloc(a, b)
Definition: header.h:55

◆ pgtypes_fmt_replace()

int pgtypes_fmt_replace ( union un_fmt_comb  ,
int  ,
char **  ,
int *   
)

Definition at line 29 of file common.c.

References un_fmt_comb::char_val, un_fmt_comb::double_val, free, i, INT64_FORMAT, un_fmt_comb::int64_val, 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().

30 {
31  /*
32  * general purpose variable, set to 0 in order to fix compiler warning
33  */
34  int i = 0;
35 
36  switch (replace_type)
37  {
39  break;
42  i = strlen(replace_val.str_val);
43  if (i + 1 <= *pstr_len)
44  {
45  /*
46  * copy over i + 1 bytes, that includes the tailing terminator
47  */
48  strncpy(*output, replace_val.str_val, i + 1);
49  *pstr_len -= i;
50  *output += i;
51  if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)
52  free(replace_val.str_val);
53  return 0;
54  }
55  else
56  return -1;
57  break;
58  case PGTYPES_TYPE_CHAR:
59  if (*pstr_len >= 2)
60  {
61  (*output)[0] = replace_val.char_val;
62  (*output)[1] = '\0';
63  (*pstr_len)--;
64  (*output)++;
65  return 0;
66  }
67  else
68  return -1;
69  break;
71  case PGTYPES_TYPE_INT64:
72  case PGTYPES_TYPE_UINT:
77  {
79 
80  if (!t)
81  return ENOMEM;
82  switch (replace_type)
83  {
86  "%0.0g", replace_val.double_val);
87  break;
88  case PGTYPES_TYPE_INT64:
90  INT64_FORMAT, replace_val.int64_val);
91  break;
92  case PGTYPES_TYPE_UINT:
94  "%u", replace_val.uint_val);
95  break;
98  "%02u", replace_val.uint_val);
99  break;
102  "%2u", replace_val.uint_val);
103  break;
106  "%03u", replace_val.uint_val);
107  break;
110  "%04u", replace_val.uint_val);
111  break;
112  }
113 
114  if (i < 0)
115  {
116  free(t);
117  return -1;
118  }
119  i = strlen(t);
120  *pstr_len -= i;
121 
122  /*
123  * if *pstr_len == 0, we don't have enough space for the
124  * terminator and the conversion fails
125  */
126  if (*pstr_len <= 0)
127  {
128  free(t);
129  return -1;
130  }
131  strcpy(*output, t);
132  *output += i;
133  free(t);
134  }
135  break;
136  default:
137  break;
138  }
139  return 0;
140 }
#define PGTYPES_TYPE_STRING_MALLOCED
Definition: extern.h:11
#define PGTYPES_TYPE_CHAR
Definition: extern.h:13
static void output(uint64 loop_count)
#define PGTYPES_TYPE_DOUBLE_NF
Definition: extern.h:14
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PGTYPES_FMT_NUM_MAX_DIGITS
Definition: extern.h:24
#define PGTYPES_TYPE_INT64
Definition: extern.h:15
char * pgtypes_alloc(long size)
Definition: common.c:9
#define PGTYPES_TYPE_UINT_4_LZ
Definition: extern.h:21
#define PGTYPES_TYPE_UINT_3_LZ
Definition: extern.h:20
#define PGTYPES_TYPE_NOTHING
Definition: extern.h:10
#define free(a)
Definition: header.h:65
#define PGTYPES_TYPE_UINT_2_LS
Definition: extern.h:18
#define PGTYPES_TYPE_UINT_2_LZ
Definition: extern.h:17
#define PGTYPES_TYPE_STRING_CONSTANT
Definition: extern.h:12
#define INT64_FORMAT
Definition: c.h:338
int i
#define PGTYPES_TYPE_UINT
Definition: extern.h:16

◆ pgtypes_strdup()

char* pgtypes_strdup ( const char *  )

Definition at line 19 of file common.c.

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

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