Go to the source code of this file.
Data Structures | |
struct | PQExpBufferData |
Defines | |
#define | PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) |
#define | PQExpBufferDataBroken(buf) ((buf).maxlen == 0) |
#define | INITIAL_EXPBUFFER_SIZE 256 |
Typedefs | |
typedef struct PQExpBufferData | PQExpBufferData |
typedef PQExpBufferData * | PQExpBuffer |
Functions | |
PQExpBuffer | createPQExpBuffer (void) |
void | initPQExpBuffer (PQExpBuffer str) |
void | destroyPQExpBuffer (PQExpBuffer str) |
void | termPQExpBuffer (PQExpBuffer str) |
void | resetPQExpBuffer (PQExpBuffer str) |
int | enlargePQExpBuffer (PQExpBuffer str, size_t needed) |
void | printfPQExpBuffer (PQExpBuffer str, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE |
void void | appendPQExpBuffer (PQExpBuffer str, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE |
void void void | appendPQExpBufferStr (PQExpBuffer str, const char *data) |
void | appendPQExpBufferChar (PQExpBuffer str, char ch) |
void | appendBinaryPQExpBuffer (PQExpBuffer str, const char *data, size_t datalen) |
#define INITIAL_EXPBUFFER_SIZE 256 |
Definition at line 76 of file pqexpbuffer.h.
Referenced by initPQExpBuffer().
#define PQExpBufferBroken | ( | str | ) | ((str) == NULL || (str)->maxlen == 0) |
Definition at line 59 of file pqexpbuffer.h.
Referenced by appendPQExpBuffer(), enlargePQExpBuffer(), GenerateRecoveryConf(), gets_fromFile(), MainLoop(), makeEmptyPGconn(), and printfPQExpBuffer().
Definition at line 67 of file pqexpbuffer.h.
Referenced by PQconndefaults(), PQconninfo(), and PQconninfoParse().
typedef PQExpBufferData* PQExpBuffer |
Definition at line 51 of file pqexpbuffer.h.
typedef struct PQExpBufferData PQExpBufferData |
void appendBinaryPQExpBuffer | ( | PQExpBuffer | str, | |
const char * | data, | |||
size_t | datalen | |||
) |
Definition at line 362 of file pqexpbuffer.c.
References PQExpBufferData::data, enlargePQExpBuffer(), and PQExpBufferData::len.
Referenced by appendPQExpBufferStr(), createViewAsClause(), and pqGets_internal().
void void appendPQExpBuffer | ( | PQExpBuffer | str, | |
const char * | fmt, | |||
... | ||||
) |
void appendPQExpBufferChar | ( | PQExpBuffer | str, | |
char | ch | |||
) |
Definition at line 343 of file pqexpbuffer.c.
References PQExpBufferData::data, enlargePQExpBuffer(), and PQExpBufferData::len.
Referenced by AddAcl(), appendStringLiteralConn(), appendStringLiteralDQ(), constructConnStr(), copyAclUserName(), do_edit(), doConnStrQuoting(), doShellQuoting(), ExecuteInsertCommands(), fmtId(), MainLoop(), pg_append_history(), PQconnectPoll(), pqGetErrorNotice3(), processSQLNamePattern(), and reportErrorPosition().
void void void appendPQExpBufferStr | ( | PQExpBuffer | str, | |
const char * | data | |||
) |
Definition at line 332 of file pqexpbuffer.c.
References appendBinaryPQExpBuffer().
Referenced by _getObjectDescription(), add_role_attribute(), appendStringLiteralDQ(), describeOneTableDetails(), describeRoles(), do_copy(), do_edit(), doConnStrQuoting(), dumpBaseType(), dumpCompositeType(), dumpDomain(), dumpEventTrigger(), dumpTableData_copy(), dumpTableData_insert(), dumpTrigger(), fmtId(), GenerateRecoveryConf(), get_create_function_cmd(), gets_fromFile(), listDbRoleSettings(), main(), MainLoop(), minimal_error_message(), pg_append_history(), pqCatenateResultError(), PQexecFinish(), pqGetErrorNotice2(), pqGetErrorNotice3(), pqPrepareAsyncResult(), processSQLNamePattern(), and reportErrorPosition().
{ appendBinaryPQExpBuffer(str, data, strlen(data)); }
PQExpBuffer createPQExpBuffer | ( | void | ) |
Definition at line 68 of file pqexpbuffer.c.
References initPQExpBuffer(), malloc, and NULL.
Referenced by _doSetSessionAuth(), _doSetWithOids(), _printTocEntry(), _reconnectToDB(), _selectOutputSchema(), _selectTablespace(), _WriteBlobData(), appendStringLiteralDQ(), binary_upgrade_set_pg_class_oids(), binary_upgrade_set_type_oids_by_rel_oid(), binary_upgrade_set_type_oids_by_type_oid(), buildACLCommands(), buildDefaultACLCommands(), buildMatViewRefreshDependencies(), buildShSecLabels(), collectComments(), collectSecLabels(), constructConnStr(), createViewAsClause(), defaultGetLocalPQExpBuffer(), dump_lo_buf(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpBlob(), dumpCast(), dumpCollation(), dumpComment(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpCreateDB(), dumpDatabase(), dumpDatabaseConfig(), dumpDbRoleConfig(), dumpDefaultACL(), dumpDomain(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpGroups(), dumpIndex(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpProcLang(), dumpRangeType(), dumpRoles(), dumpRule(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStdStrings(), dumpTable(), dumpTableComment(), dumpTableConstraintComment(), dumpTableData(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUserConfig(), dumpUserMappings(), exec_command(), ExecuteInsertCommands(), expand_schema_name_patterns(), expand_table_name_patterns(), findLastBuiltinOid_V71(), fmtQualifiedId(), GenerateRecoveryConf(), get_create_function_cmd(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFormattedTypeName(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getProcLangs(), getRules(), gets_fromFile(), getTableAttrs(), getTables(), getThreadLocalPQExpBuffer(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), lockTableNoWait(), lookup_function_oid(), main(), MainLoop(), makeAlterConfigCommand(), minimal_error_message(), myFormatType(), refreshMatViewData(), runPgDump(), selectSourceSchema(), and setup_connection().
{ PQExpBuffer res; res = (PQExpBuffer) malloc(sizeof(PQExpBufferData)); if (res != NULL) initPQExpBuffer(res); return res; }
void destroyPQExpBuffer | ( | PQExpBuffer | str | ) |
Definition at line 110 of file pqexpbuffer.c.
References free, and termPQExpBuffer().
Referenced by _doSetSessionAuth(), _doSetWithOids(), _printTocEntry(), _reconnectToDB(), _selectOutputSchema(), _selectTablespace(), _WriteBlobData(), appendStringLiteralDQ(), BaseBackup(), binary_upgrade_set_pg_class_oids(), binary_upgrade_set_type_oids_by_rel_oid(), binary_upgrade_set_type_oids_by_type_oid(), buildACLCommands(), buildDefaultACLCommands(), buildMatViewRefreshDependencies(), buildShSecLabels(), collectComments(), collectSecLabels(), constructConnStr(), createViewAsClause(), DeCloneArchive(), dump_lo_buf(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpBlob(), dumpCast(), dumpCollation(), dumpComment(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpCreateDB(), dumpDatabase(), dumpDatabaseConfig(), dumpDbRoleConfig(), dumpDefaultACL(), dumpDomain(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpGroups(), dumpIndex(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpProcLang(), dumpRangeType(), dumpRoles(), dumpRule(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStdStrings(), dumpTable(), dumpTableComment(), dumpTableConstraintComment(), dumpTableData(), dumpTableData_copy(), dumpTableData_insert(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUserConfig(), dumpUserMappings(), exec_command(), expand_schema_name_patterns(), expand_table_name_patterns(), findLastBuiltinOid_V71(), fmtQualifiedId(), get_create_function_cmd(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDependencies(), getDomainConstraints(), getEventTriggers(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFormattedTypeName(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getProcLangs(), getRules(), getTableAttrs(), getTables(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), lockTableNoWait(), lookup_function_oid(), main(), MainLoop(), makeAlterConfigCommand(), minimal_error_message(), myFormatType(), refreshMatViewData(), runPgDump(), selectSourceSchema(), and setup_connection().
{ if (str) { termPQExpBuffer(str); free(str); } }
int enlargePQExpBuffer | ( | PQExpBuffer | str, | |
size_t | needed | |||
) |
Definition at line 168 of file pqexpbuffer.c.
References PQExpBufferData::data, PQExpBufferData::len, markPQExpBufferBroken(), PQExpBufferData::maxlen, NULL, PQExpBufferBroken, and realloc.
Referenced by appendBinaryPQExpBuffer(), appendByteaLiteral(), appendPQExpBuffer(), appendPQExpBufferChar(), appendStringLiteral(), appendStringLiteralConn(), and printfPQExpBuffer().
{ size_t newlen; char *newdata; if (PQExpBufferBroken(str)) return 0; /* already failed */ /* * Guard against ridiculous "needed" values, which can occur if we're fed * bogus data. Without this, we can get an overflow or infinite loop in * the following. */ if (needed >= ((size_t) INT_MAX - str->len)) { markPQExpBufferBroken(str); return 0; } needed += str->len + 1; /* total space required now */ /* Because of the above test, we now have needed <= INT_MAX */ if (needed <= str->maxlen) return 1; /* got enough space already */ /* * We don't want to allocate just a little more space with each append; * for efficiency, double the buffer size each time it overflows. * Actually, we might need to more than double it if 'needed' is big... */ newlen = (str->maxlen > 0) ? (2 * str->maxlen) : 64; while (needed > newlen) newlen = 2 * newlen; /* * Clamp to INT_MAX in case we went past it. Note we are assuming here * that INT_MAX <= UINT_MAX/2, else the above loop could overflow. We * will still have newlen >= needed. */ if (newlen > (size_t) INT_MAX) newlen = (size_t) INT_MAX; newdata = (char *) realloc(str->data, newlen); if (newdata != NULL) { str->data = newdata; str->maxlen = newlen; return 1; } markPQExpBufferBroken(str); return 0; }
void initPQExpBuffer | ( | PQExpBuffer | str | ) |
Definition at line 86 of file pqexpbuffer.c.
References PQExpBufferData::data, INITIAL_EXPBUFFER_SIZE, PQExpBufferData::len, malloc, PQExpBufferData::maxlen, NULL, and oom_buffer.
Referenced by add_tablespace_footer(), cluster_one_database(), createPQExpBuffer(), describeAggregates(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describeRoles(), describeTableDetails(), describeTablespaces(), describeTypes(), do_copy(), exec_command(), ExecQueryUsingCursor(), format_aggregate_signature(), format_function_arguments(), format_function_arguments_old(), format_function_signature(), getCasts(), getParameterStatus(), helpSQL(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), makeEmptyPGconn(), objectDescription(), permissionsList(), pqCatenateResultError(), PQconndefaults(), PQconninfo(), PQconninfoParse(), pqGetErrorNotice2(), pqGetErrorNotice3(), processSQLNamePattern(), reindex_one_database(), reindex_system_catalogs(), resetPQExpBuffer(), and vacuum_one_database().
void printfPQExpBuffer | ( | PQExpBuffer | str, | |
const char * | fmt, | |||
... | ||||
) |
void resetPQExpBuffer | ( | PQExpBuffer | str | ) |
Definition at line 142 of file pqexpbuffer.c.
References PQExpBufferData::data, initPQExpBuffer(), PQExpBufferData::len, and oom_buffer.
Referenced by connectDBComplete(), copyAclUserName(), defaultGetLocalPQExpBuffer(), describeOneTableDetails(), describeRoles(), do_edit(), dumpBlob(), dumpCompositeTypeColComments(), dumpCreateDB(), dumpDatabase(), dumpOpclass(), dumpOpfamily(), dumpRoles(), dumpSequence(), dumpSequenceData(), dumpTableComment(), dumpTableData_insert(), dumpTableSecLabel(), dumpTSConfig(), dumpUserMappings(), exec_command(), ExecuteInsertCommands(), findLastBuiltinOid_V71(), get_create_function_cmd(), getConstraints(), getIndexes(), gets_fromFile(), getTableAttrs(), getTables(), getThreadLocalPQExpBuffer(), getTriggers(), listDbRoleSettings(), lockTableNoWait(), MainLoop(), parseAclItem(), pg_send_history(), pqEndcopy2(), pqEndcopy3(), PQexecFinish(), PQfn(), pqGetErrorNotice2(), pqGetErrorNotice3(), pqGets_internal(), pqPrepareAsyncResult(), PQputCopyEnd(), PQsendQueryStart(), printfPQExpBuffer(), and processSQLNamePattern().
{ if (str) { if (str->data != oom_buffer) { str->len = 0; str->data[0] = '\0'; } else { /* try to reinitialize to valid state */ initPQExpBuffer(str); } } }
void termPQExpBuffer | ( | PQExpBuffer | str | ) |
Definition at line 125 of file pqexpbuffer.c.
References PQExpBufferData::data, free, PQExpBufferData::len, PQExpBufferData::maxlen, and oom_buffer.
Referenced by add_tablespace_footer(), cluster_one_database(), describeAggregates(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describeRoles(), describeTableDetails(), describeTablespaces(), describeTypes(), destroyPQExpBuffer(), do_copy(), exec_command(), ExecQueryUsingCursor(), freePGconn(), getParameterStatus(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listOneExtensionContents(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), objectDescription(), permissionsList(), pqCatenateResultError(), PQconndefaults(), PQconninfo(), PQconninfoParse(), pqGetErrorNotice2(), pqGetErrorNotice3(), processSQLNamePattern(), reindex_one_database(), reindex_system_catalogs(), and vacuum_one_database().
{ if (str->data != oom_buffer) free(str->data); /* just for luck, make the buffer validly empty. */ str->data = (char *) oom_buffer; /* see comment above */ str->maxlen = 0; str->len = 0; }