#include "dpiImpl.h"
void dpiStringList__free(dpiStringList *list)
{
uint32_t i;
if (list->strings) {
for (i = 0; i < list->numStrings; i++)
dpiUtils__freeMemory((void*) list->strings[i]);
dpiUtils__freeMemory((void*) list->strings);
list->strings = NULL;
}
if (list->stringLengths) {
dpiUtils__freeMemory(list->stringLengths);
list->stringLengths = NULL;
}
list->numStrings = 0;
}
int dpiStringList__addElement(dpiStringList *list, const char *value,
uint32_t valueLength, uint32_t *numStringsAllocated, dpiError *error)
{
uint32_t *tempStringLengths;
char **tempStrings;
char *ptr;
if (*numStringsAllocated <= list->numStrings) {
*numStringsAllocated += 64;
if (dpiUtils__allocateMemory(*numStringsAllocated, sizeof(uint32_t), 0,
"allocate lengths array", (void**) &tempStringLengths,
error) < 0)
return DPI_FAILURE;
if (list->stringLengths) {
memcpy(tempStringLengths, list->stringLengths,
list->numStrings * sizeof(uint32_t));
dpiUtils__freeMemory(list->stringLengths);
}
list->stringLengths = tempStringLengths;
if (dpiUtils__allocateMemory(*numStringsAllocated, sizeof(char*), 0,
"allocate strings array", (void**) &tempStrings, error) < 0)
return DPI_FAILURE;
if (list->strings) {
memcpy(tempStrings, list->strings,
list->numStrings * sizeof(char*));
dpiUtils__freeMemory((void*) list->strings);
}
list->strings = (const char**) tempStrings;
}
if (dpiUtils__allocateMemory(valueLength, 1, 0, "allocate string",
(void**) &ptr, error) < 0)
return DPI_FAILURE;
memcpy(ptr, value, valueLength);
list->strings[list->numStrings] = ptr;
list->stringLengths[list->numStrings] = valueLength;
list->numStrings++;
return DPI_SUCCESS;
}