Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Functions

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

Defines

#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
#define PGTYPES_TYPE_INT64   5
#define PGTYPES_TYPE_UINT   6
#define PGTYPES_TYPE_UINT_2_LZ   7
#define PGTYPES_TYPE_UINT_2_LS   8
#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 *)

Define Documentation

#define bool   char

Definition at line 43 of file extern.h.

#define FALSE   0

Definition at line 47 of file extern.h.

#define PGTYPES_FMT_NUM_MAX_DIGITS   40

Definition at line 25 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_CHAR   3

Definition at line 13 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_DOUBLE_NF   4

Definition at line 14 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_INT64   5

Definition at line 15 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_NOTHING   0

Definition at line 10 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_STRING_CONSTANT   2

Definition at line 12 of file extern.h.

Referenced by pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

#define PGTYPES_TYPE_STRING_MALLOCED   1

Definition at line 11 of file extern.h.

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

#define PGTYPES_TYPE_UINT   6

Definition at line 16 of file extern.h.

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

#define PGTYPES_TYPE_UINT_2_LS   8

Definition at line 19 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_UINT_2_LZ   7

Definition at line 17 of file extern.h.

Referenced by pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

#define PGTYPES_TYPE_UINT_3_LZ   9

Definition at line 21 of file extern.h.

Referenced by pgtypes_fmt_replace().

#define PGTYPES_TYPE_UINT_4_LZ   10

Definition at line 22 of file extern.h.

Referenced by pgtypes_fmt_replace(), and PGTYPESdate_fmt_asc().

#define PGTYPES_TYPE_UINT_LONG   11

Definition at line 23 of file extern.h.

Referenced by pgtypes_defmt_scan().

#define TRUE   1

Definition at line 51 of file extern.h.


Function Documentation

char* pgtypes_alloc ( long   ) 
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, 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().

{
    /*
     * general purpose variable, set to 0 in order to fix compiler warning
     */
    int         i = 0;

    switch (replace_type)
    {
        case PGTYPES_TYPE_NOTHING:
            break;
        case PGTYPES_TYPE_STRING_CONSTANT:
        case PGTYPES_TYPE_STRING_MALLOCED:
            i = strlen(replace_val.str_val);
            if (i + 1 <= *pstr_len)
            {
                /*
                 * copy over i + 1 bytes, that includes the tailing terminator
                 */
                strncpy(*output, replace_val.str_val, i + 1);
                *pstr_len -= i;
                *output += i;
                if (replace_type == PGTYPES_TYPE_STRING_MALLOCED)
                    free(replace_val.str_val);
                return 0;
            }
            else
                return -1;
            break;
        case PGTYPES_TYPE_CHAR:
            if (*pstr_len >= 2)
            {
                (*output)[0] = replace_val.char_val;
                (*output)[1] = '\0';
                (*pstr_len)--;
                (*output)++;
                return 0;
            }
            else
                return -1;
            break;
        case PGTYPES_TYPE_DOUBLE_NF:
        case PGTYPES_TYPE_INT64:
        case PGTYPES_TYPE_UINT:
        case PGTYPES_TYPE_UINT_2_LZ:
        case PGTYPES_TYPE_UINT_2_LS:
        case PGTYPES_TYPE_UINT_3_LZ:
        case PGTYPES_TYPE_UINT_4_LZ:
            {
                char       *t = pgtypes_alloc(PGTYPES_FMT_NUM_MAX_DIGITS);

                if (!t)
                    return ENOMEM;
                switch (replace_type)
                {
                    case PGTYPES_TYPE_DOUBLE_NF:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%0.0g", replace_val.double_val);
                        break;
                    case PGTYPES_TYPE_INT64:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     INT64_FORMAT, replace_val.int64_val);
                        break;
                    case PGTYPES_TYPE_UINT:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%u", replace_val.uint_val);
                        break;
                    case PGTYPES_TYPE_UINT_2_LZ:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%02u", replace_val.uint_val);
                        break;
                    case PGTYPES_TYPE_UINT_2_LS:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%2u", replace_val.uint_val);
                        break;
                    case PGTYPES_TYPE_UINT_3_LZ:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%03u", replace_val.uint_val);
                        break;
                    case PGTYPES_TYPE_UINT_4_LZ:
                        i = snprintf(t, PGTYPES_FMT_NUM_MAX_DIGITS,
                                     "%04u", replace_val.uint_val);
                        break;
                }

                if (i < 0)
                {
                    free(t);
                    return -1;
                }
                i = strlen(t);
                *pstr_len -= i;

                /*
                 * if *pstr_len == 0, we don't have enough space for the
                 * terminator and the conversion fails
                 */
                if (*pstr_len <= 0)
                {
                    free(t);
                    return -1;
                }
                strcpy(*output, t);
                *output += i;
                free(t);
            }
            break;
        default:
            break;
    }
    return 0;
}

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

{
    char       *new = (char *) strdup(str);

    if (!new)
        errno = ENOMEM;
    return (new);
}