summaryrefslogtreecommitdiffstats
path: root/srUtils.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-03 17:37:28 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-03 17:37:28 +0000
commitb95b5ab28407b75467c6cff63359cba9a0a3bd70 (patch)
treee5ec5564b97690f1a278f1d693f7390d5818623d /srUtils.c
parent64de2f0d2e0dd61dc9703a4ffd62f41f5cf42caa (diff)
downloadrsyslog-b95b5ab28407b75467c6cff63359cba9a0a3bd70.tar.gz
rsyslog-b95b5ab28407b75467c6cff63359cba9a0a3bd70.tar.xz
rsyslog-b95b5ab28407b75467c6cff63359cba9a0a3bd70.zip
begun working on disk queueing (not completed, do not use this mode!)
Diffstat (limited to 'srUtils.c')
-rwxr-xr-xsrUtils.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/srUtils.c b/srUtils.c
index c10f58bb..a0dae0b7 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -7,7 +7,7 @@
* \date 2003-09-09
* Coding begun.
*
- * Copyright 2003-2007 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2003-2008 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -238,6 +238,55 @@ void skipWhiteSpace(uchar **pp)
}
+/* generate a file name from four parts:
+ * <directory name>/<prefix>-<number>.<type>
+ * If number is negative, it is not used. If any of the strings is
+ * NULL, an empty string is used instead. Length must be provided.
+ * rgerhards, 2008-01-03
+ */
+rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName,
+ uchar *pPrefix, size_t lenPrefix, long lNum, uchar *pType, size_t lenType)
+{
+ DEFiRet;
+ uchar *pName;
+ uchar *pNameWork;
+ size_t lenName;
+ uchar szBuf[128]; /* buffer for number */
+ size_t lenBuf;
+
+ if(lNum < 0) {
+ szBuf[0] = '\0';
+ lenBuf = 0;
+ } else {
+ lenBuf = snprintf((char*)szBuf, sizeof(szBuf), "-%ld", lNum);
+ }
+
+ lenName = lenDirName + 1 + lenPrefix + lenBuf + 1 + lenType + 1; /* last +1 for \0 char! */
+ if((pName = malloc(sizeof(uchar) * lenName)) == NULL)
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+
+ /* got memory, now construct string */
+ memcpy(pName, pDirName, lenDirName);
+ pNameWork = pName + lenDirName;
+ *pNameWork++ = '/';
+ memcpy(pNameWork, pPrefix, lenPrefix);
+ pNameWork += lenPrefix;
+ if(lenBuf > 0) {
+ memcpy(pNameWork, szBuf, lenBuf);
+ pNameWork += lenBuf;
+ }
+ *pNameWork++ = '.';
+ memcpy(pNameWork, pType, lenType);
+ pNameWork += lenType;
+ *pNameWork = '\0';
+
+ *ppName = pName;
+
+finalize_it:
+ return iRet;
+}
+
+
/*
* vi:set ai:
*/