summaryrefslogtreecommitdiffstats
path: root/stringbuf.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-02-19 10:30:42 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-02-19 10:30:42 +0000
commitcd2b24dfc45c4b115ace6d17ab0237511fef3d66 (patch)
treede8436b5397e4248327bbddbb223d9dec6fef1ef /stringbuf.c
parent80b1798e2ddaf9ee4090321dba7465f233207682 (diff)
downloadrsyslog-cd2b24dfc45c4b115ace6d17ab0237511fef3d66.tar.gz
rsyslog-cd2b24dfc45c4b115ace6d17ab0237511fef3d66.tar.xz
rsyslog-cd2b24dfc45c4b115ace6d17ab0237511fef3d66.zip
- added doc on how expressions will work
- cleaned up the stringbuf Construct interface - did some cleanup on stringbuf calls - we now have much better interfaces and macros
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-xstringbuf.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/stringbuf.c b/stringbuf.c
index 7f3575cf..237355c0 100755
--- a/stringbuf.c
+++ b/stringbuf.c
@@ -50,12 +50,15 @@
* ################################################################# */
-rsCStrObj *rsCStrConstruct(void)
+rsRetVal rsCStrConstruct(rsCStrObj **ppThis)
{
+ DEFiRet;
rsCStrObj *pThis;
+ ASSERT(ppThis != NULL);
+
if((pThis = (rsCStrObj*) calloc(1, sizeof(rsCStrObj))) == NULL)
- return NULL;
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
rsSETOBJTYPE(pThis, OIDrsCStr);
pThis->pBuf = NULL;
@@ -63,33 +66,38 @@ rsCStrObj *rsCStrConstruct(void)
pThis->iBufSize = 0;
pThis->iStrLen = 0;
pThis->iAllocIncrement = RS_STRINGBUF_ALLOC_INCREMENT;
+ *ppThis = pThis;
- return pThis;
+finalize_it:
+ RETiRet;
}
+
/* construct from sz string
* rgerhards 2005-09-15
*/
rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz)
{
+ DEFiRet;
rsCStrObj *pThis;
assert(ppThis != NULL);
- if((pThis = rsCStrConstruct()) == NULL)
- return RS_RET_OUT_OF_MEMORY;
+ CHKiRet(rsCStrConstruct(&pThis));
pThis->iBufSize = pThis->iStrLen = strlen((char*)(char *) sz);
if((pThis->pBuf = (uchar*) malloc(sizeof(uchar) * pThis->iStrLen)) == NULL) {
RSFREEOBJ(pThis);
- return RS_RET_OUT_OF_MEMORY;
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
}
/* we do NOT need to copy the \0! */
memcpy(pThis->pBuf, sz, pThis->iStrLen);
*ppThis = pThis;
- return RS_RET_OK;
+
+finalize_it:
+ RETiRet;
}
/* construct from CStr object. only the counted string is
@@ -98,25 +106,26 @@ rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz)
*/
rsRetVal rsCStrConstructFromCStr(rsCStrObj **ppThis, rsCStrObj *pFrom)
{
+ DEFiRet;
rsCStrObj *pThis;
assert(ppThis != NULL);
rsCHECKVALIDOBJECT(pFrom, OIDrsCStr);
- if((pThis = rsCStrConstruct()) == NULL)
- return RS_RET_OUT_OF_MEMORY;
+ CHKiRet(rsCStrConstruct(&pThis));
pThis->iBufSize = pThis->iStrLen = pFrom->iStrLen;
if((pThis->pBuf = (uchar*) malloc(sizeof(uchar) * pThis->iStrLen)) == NULL) {
RSFREEOBJ(pThis);
- return RS_RET_OUT_OF_MEMORY;
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
}
/* copy properties */
memcpy(pThis->pBuf, pFrom->pBuf, pThis->iStrLen);
*ppThis = pThis;
- return RS_RET_OK;
+finalize_it:
+ RETiRet;
}