summaryrefslogtreecommitdiffstats
path: root/runtime/stringbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/stringbuf.c')
-rw-r--r--runtime/stringbuf.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index e11d0e3b..5bca009d 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -33,6 +33,7 @@
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
+#include <libestr.h>
#include "rsyslog.h"
#include "stringbuf.h"
#include "srUtils.h"
@@ -102,6 +103,34 @@ finalize_it:
RETiRet;
}
+
+/* construct from es_str_t string
+ * rgerhards 2010-12-03
+ */
+rsRetVal cstrConstructFromESStr(cstr_t **ppThis, es_str_t *str)
+{
+ DEFiRet;
+ cstr_t *pThis;
+
+ assert(ppThis != NULL);
+
+ CHKiRet(rsCStrConstruct(&pThis));
+
+ pThis->iBufSize = pThis->iStrLen = es_strlen(str);
+ if((pThis->pBuf = (uchar*) MALLOC(sizeof(uchar) * pThis->iStrLen)) == NULL) {
+ RSFREEOBJ(pThis);
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+
+ /* we do NOT need to copy the \0! */
+ memcpy(pThis->pBuf, es_getBufAddr(str), pThis->iStrLen);
+
+ *ppThis = pThis;
+
+finalize_it:
+ RETiRet;
+}
+
/* construct from CStr object. only the counted string is
* copied, not the szString.
* rgerhards 2005-10-18
@@ -453,6 +482,8 @@ rsRetVal cstrTrimTrailingWhiteSpace(cstr_t *pThis)
register uchar *pC;
rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+ if(pThis->iStrLen == 0)
+ goto done; /* empty string -> nothing to trim ;) */
i = pThis->iStrLen;
pC = pThis->pBuf + i - 1;
while(i > 0 && isspace((int)*pC)) {
@@ -463,7 +494,7 @@ rsRetVal cstrTrimTrailingWhiteSpace(cstr_t *pThis)
pThis->iStrLen = i;
pThis->pBuf[pThis->iStrLen] = '0'; /* we always have this space */
- return RS_RET_OK;
+done: return RS_RET_OK;
}
/* compare two string objects - works like strcmp(), but operates