diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-24 10:52:06 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-24 10:52:06 +0200 |
commit | 8eb10a7105dce1dc3ffc44b291de73d82bd04799 (patch) | |
tree | e3c70740599127009b6009a2846d8274e67c8900 /runtime/srutils.c | |
parent | 675d46f5b59f64e378968baa5e0dec6810090287 (diff) | |
parent | c53ca3a23429e750aeb6ab1c3600ae8ecb3c8ac6 (diff) | |
download | rsyslog-8eb10a7105dce1dc3ffc44b291de73d82bd04799.tar.gz rsyslog-8eb10a7105dce1dc3ffc44b291de73d82bd04799.tar.bz2 rsyslog-8eb10a7105dce1dc3ffc44b291de73d82bd04799.zip |
Merge branch 'omfile'
Conflicts:
ChangeLog
Diffstat (limited to 'runtime/srutils.c')
-rw-r--r-- | runtime/srutils.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/srutils.c b/runtime/srutils.c index d01ca20d..5407531f 100644 --- a/runtime/srutils.c +++ b/runtime/srutils.c @@ -553,6 +553,33 @@ int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep) } +/* get the size of a file or return appropriate error code. If an error is returned, + * *pSize content is undefined. + * rgerhards, 2009-06-12 + */ +rsRetVal +getFileSize(uchar *pszName, off_t *pSize) +{ + int ret; + struct stat statBuf; + DEFiRet; + + ret = stat((char*) pszName, &statBuf); + if(ret == -1) { + switch(errno) { + case EACCES: ABORT_FINALIZE(RS_RET_NO_FILE_ACCESS); + case ENOTDIR: + case ENOENT: ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND); + default: ABORT_FINALIZE(RS_RET_FILE_NO_STAT); + } + } + + *pSize = statBuf.st_size; + +finalize_it: + RETiRet; +} + /* vim:set ai: */ |