* appendBinaryStringInfo
*
* Append arbitrary binary data to a StringInfo, allocating more space
- * if necessary.
+ * if necessary. Ensures that a trailing null byte is present.
*/
void
appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
str->data[str->len] = '\0';
}
+/*
+ * appendBinaryStringInfoNT
+ *
+ * Append arbitrary binary data to a StringInfo, allocating more space
+ * if necessary. Does not ensure a trailing null-byte exists.
+ */
+void
+appendBinaryStringInfoNT(StringInfo str, const char *data, int datalen)
+{
+ Assert(str != NULL);
+
+ /* Make more room if needed */
+ enlargeStringInfo(str, datalen);
+
+ /* OK, append the data */
+ memcpy(str->data + str->len, data, datalen);
+ str->len += datalen;
+}
+
/*
* enlargeStringInfo
*
{
slen = strlen(p);
pq_sendint(buf, slen + extra, 4);
- appendBinaryStringInfo(buf, p, slen);
+ appendBinaryStringInfoNT(buf, p, slen);
pfree(p);
}
else
{
pq_sendint(buf, slen + extra, 4);
- appendBinaryStringInfo(buf, str, slen);
+ appendBinaryStringInfoNT(buf, str, slen);
}
}
if (p != str) /* actual conversion has been done? */
{
slen = strlen(p);
- appendBinaryStringInfo(buf, p, slen + 1);
+ appendBinaryStringInfoNT(buf, p, slen + 1);
pfree(p);
}
else
- appendBinaryStringInfo(buf, str, slen + 1);
+ appendBinaryStringInfoNT(buf, str, slen + 1);
}
/* --------------------------------
{
case 1:
n8 = (unsigned char) i;
- appendBinaryStringInfo(buf, (char *) &n8, 1);
+ appendBinaryStringInfoNT(buf, (char *) &n8, 1);
break;
case 2:
n16 = pg_hton16((uint16) i);
- appendBinaryStringInfo(buf, (char *) &n16, 2);
+ appendBinaryStringInfoNT(buf, (char *) &n16, 2);
break;
case 4:
n32 = pg_hton32((uint32) i);
- appendBinaryStringInfo(buf, (char *) &n32, 4);
+ appendBinaryStringInfoNT(buf, (char *) &n32, 4);
break;
default:
elog(ERROR, "unsupported integer size %d", b);
{
uint64 n64 = pg_hton64(i);
- appendBinaryStringInfo(buf, (char *) &n64, sizeof(n64));
+ appendBinaryStringInfoNT(buf, (char *) &n64, sizeof(n64));
}
/* --------------------------------
swap.f = f;
swap.i = pg_hton32(swap.i);
- appendBinaryStringInfo(buf, (char *) &swap.i, 4);
+ appendBinaryStringInfoNT(buf, (char *) &swap.i, 4);
}
/* --------------------------------
extern void appendBinaryStringInfo(StringInfo str,
const char *data, int datalen);
+/*------------------------
+ * appendBinaryStringInfoNT
+ * Append arbitrary binary data to a StringInfo, allocating more space
+ * if necessary. Does not ensure a trailing null-byte exists.
+ */
+extern void appendBinaryStringInfoNT(StringInfo str,
+ const char *data, int datalen);
+
/*------------------------
* enlargeStringInfo
* Make sure a StringInfo's buffer can hold at least 'needed' more bytes.