diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-03 17:37:28 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-03 17:37:28 +0000 |
commit | b95b5ab28407b75467c6cff63359cba9a0a3bd70 (patch) | |
tree | e5ec5564b97690f1a278f1d693f7390d5818623d /srUtils.c | |
parent | 64de2f0d2e0dd61dc9703a4ffd62f41f5cf42caa (diff) | |
download | rsyslog-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-x | srUtils.c | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -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: */ |