Annotation of parser3/src/sql/pgsql/PgSQL32/include/pqexpbuffer.h, revision 1.1
1.1 ! parser 1: /*-------------------------------------------------------------------------
! 2: *
! 3: * pqexpbuffer.h
! 4: * Declarations/definitions for "PQExpBuffer" functions.
! 5: *
! 6: * PQExpBuffer provides an indefinitely-extensible string data type.
! 7: * It can be used to buffer either ordinary C strings (null-terminated text)
! 8: * or arbitrary binary data. All storage is allocated with malloc().
! 9: *
! 10: * This module is essentially the same as the backend's StringInfo data type,
! 11: * but it is intended for use in frontend libpq and client applications.
! 12: * Thus, it does not rely on palloc() nor elog().
! 13: *
! 14: * It does rely on vsnprintf(); if configure finds that libc doesn't provide
! 15: * a usable vsnprintf(), then a copy of our own implementation of it will
! 16: * be linked into libpq.
! 17: *
! 18: * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
! 19: * Portions Copyright (c) 1994, Regents of the University of California
! 20: *
! 21: * $Id: pqexpbuffer.h,v 1.6 2001/01/24 19:43:31 momjian Exp $
! 22: *
! 23: *-------------------------------------------------------------------------
! 24: */
! 25: #ifndef PQEXPBUFFER_H
! 26: #define PQEXPBUFFER_H
! 27:
! 28: /*-------------------------
! 29: * PQExpBufferData holds information about an extensible string.
! 30: * data is the current buffer for the string (allocated with malloc).
! 31: * len is the current string length. There is guaranteed to be
! 32: * a terminating '\0' at data[len], although this is not very
! 33: * useful when the string holds binary data rather than text.
! 34: * maxlen is the allocated size in bytes of 'data', i.e. the maximum
! 35: * string size (including the terminating '\0' char) that we can
! 36: * currently store in 'data' without having to reallocate
! 37: * more space. We must always have maxlen > len.
! 38: *-------------------------
! 39: */
! 40: typedef struct PQExpBufferData
! 41: {
! 42: char *data;
! 43: size_t len;
! 44: size_t maxlen;
! 45: } PQExpBufferData;
! 46:
! 47: typedef PQExpBufferData *PQExpBuffer;
! 48:
! 49: /*------------------------
! 50: * Initial size of the data buffer in a PQExpBuffer.
! 51: * NB: this must be large enough to hold error messages that might
! 52: * be returned by PQrequestCancel() or any routine in fe-auth.c.
! 53: *------------------------
! 54: */
! 55: #define INITIAL_EXPBUFFER_SIZE 256
! 56:
! 57: /*------------------------
! 58: * There are two ways to create a PQExpBuffer object initially:
! 59: *
! 60: * PQExpBuffer stringptr = createPQExpBuffer();
! 61: * Both the PQExpBufferData and the data buffer are malloc'd.
! 62: *
! 63: * PQExpBufferData string;
! 64: * initPQExpBuffer(&string);
! 65: * The data buffer is malloc'd but the PQExpBufferData is presupplied.
! 66: * This is appropriate if the PQExpBufferData is a field of another
! 67: * struct.
! 68: *-------------------------
! 69: */
! 70:
! 71: /*------------------------
! 72: * createPQExpBuffer
! 73: * Create an empty 'PQExpBufferData' & return a pointer to it.
! 74: */
! 75: extern PQExpBuffer createPQExpBuffer(void);
! 76:
! 77: /*------------------------
! 78: * initPQExpBuffer
! 79: * Initialize a PQExpBufferData struct (with previously undefined contents)
! 80: * to describe an empty string.
! 81: */
! 82: extern void initPQExpBuffer(PQExpBuffer str);
! 83:
! 84: /*------------------------
! 85: * To destroy a PQExpBuffer, use either:
! 86: *
! 87: * destroyPQExpBuffer(str);
! 88: * free()s both the data buffer and the PQExpBufferData.
! 89: * This is the inverse of createPQExpBuffer().
! 90: *
! 91: * termPQExpBuffer(str)
! 92: * free()s the data buffer but not the PQExpBufferData itself.
! 93: * This is the inverse of initPQExpBuffer().
! 94: *
! 95: * NOTE: some routines build up a string using PQExpBuffer, and then
! 96: * release the PQExpBufferData but return the data string itself to their
! 97: * caller. At that point the data string looks like a plain malloc'd
! 98: * string.
! 99: */
! 100: extern void destroyPQExpBuffer(PQExpBuffer str);
! 101: extern void termPQExpBuffer(PQExpBuffer str);
! 102:
! 103: /*------------------------
! 104: * resetPQExpBuffer
! 105: * Reset a PQExpBuffer to empty
! 106: */
! 107: extern void resetPQExpBuffer(PQExpBuffer str);
! 108:
! 109: /*------------------------
! 110: * enlargePQExpBuffer
! 111: * Make sure there is enough space for 'needed' more bytes in the buffer
! 112: * ('needed' does not include the terminating null).
! 113: *
! 114: * Returns 1 if OK, 0 if failed to enlarge buffer.
! 115: */
! 116: extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed);
! 117:
! 118: /*------------------------
! 119: * printfPQExpBuffer
! 120: * Format text data under the control of fmt (an sprintf-like format string)
! 121: * and insert it into str. More space is allocated to str if necessary.
! 122: * This is a convenience routine that does the same thing as
! 123: * resetPQExpBuffer() followed by appendPQExpBuffer().
! 124: */
! 125: extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...);
! 126:
! 127: /*------------------------
! 128: * appendPQExpBuffer
! 129: * Format text data under the control of fmt (an sprintf-like format string)
! 130: * and append it to whatever is already in str. More space is allocated
! 131: * to str if necessary. This is sort of like a combination of sprintf and
! 132: * strcat.
! 133: */
! 134: extern void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...);
! 135:
! 136: /*------------------------
! 137: * appendPQExpBufferStr
! 138: * Append the given string to a PQExpBuffer, allocating more space
! 139: * if necessary.
! 140: */
! 141: extern void appendPQExpBufferStr(PQExpBuffer str, const char *data);
! 142:
! 143: /*------------------------
! 144: * appendPQExpBufferChar
! 145: * Append a single byte to str.
! 146: * Like appendPQExpBuffer(str, "%c", ch) but much faster.
! 147: */
! 148: extern void appendPQExpBufferChar(PQExpBuffer str, char ch);
! 149:
! 150: /*------------------------
! 151: * appendBinaryPQExpBuffer
! 152: * Append arbitrary binary data to a PQExpBuffer, allocating more space
! 153: * if necessary.
! 154: */
! 155: extern void appendBinaryPQExpBuffer(PQExpBuffer str,
! 156: const char *data, size_t datalen);
! 157:
! 158: #endif /* PQEXPBUFFER_H */
E-mail: