diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-01-25 20:22:22 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-01-25 20:22:22 +0100 |
commit | cf270ab62c9cb44ffd3d259b2ac1acf865f63258 (patch) | |
tree | a35eb5327974da2013deb25696c0e48f5e7a6592 | |
parent | cbe28545f9b435df3169167a95235916c5f0feb9 (diff) | |
download | embedlog-cf270ab62c9cb44ffd3d259b2ac1acf865f63258.tar.gz embedlog-cf270ab62c9cb44ffd3d259b2ac1acf865f63258.tar.bz2 embedlog-cf270ab62c9cb44ffd3d259b2ac1acf865f63258.zip |
fix: ftell after fopen(s, "a") not always points to end of file
ftell position can either end of begin of file, it implementation
specific (check stdio(3))
-rw-r--r-- | src/el-file.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/el-file.c b/src/el-file.c index fd5d916..79b7279 100644 --- a/src/el-file.c +++ b/src/el-file.c @@ -273,9 +273,9 @@ int el_file_open /* * file rotation is enabled, in such case we need to find, oldest * rotate file, as app could have been restarted, and we surely - * don't want to overwrite the newest file. Newest file has suffix - * .0 while the oldest one has suffix .${frotate_number} (or less - * if there is less files). + * don't want to overwrite the newest file. Oldest file has suffix + * .0 while the newest one has suffix .${frotate_number} (or less + * if there are less files). */ for (i = options->frotate_number - 1; i >= 0; --i) @@ -308,6 +308,13 @@ int el_file_open return -1; } + /* + * position returned by ftell is implementation specific + * (stdio(3)), it can be either end or begin of file. + */ + + fseek(f, 0, SEEK_END); + if (i == 0) { /* |