forked from github/server
Merge pull request #537 from ennorehling/develop
CID 141509 Unchecked return value from library
This commit is contained in:
commit
851ae00835
|
@ -93,25 +93,34 @@ cp_convert(const char *format, char *buffer, size_t length, int codepage)
|
||||||
void log_rotate(const char *filename, int maxindex)
|
void log_rotate(const char *filename, int maxindex)
|
||||||
{
|
{
|
||||||
char buffer[2][MAX_PATH];
|
char buffer[2][MAX_PATH];
|
||||||
int err, dst = 1;
|
int dst = 1;
|
||||||
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
||||||
|
|
||||||
sprintf(buffer[dst], "%s.%d", filename, maxindex);
|
sprintf(buffer[dst], "%s.%d", filename, maxindex);
|
||||||
/* make sure we don't overwrite an existing file (hard links) */
|
/* make sure we don't overwrite an existing file (hard links) */
|
||||||
remove(buffer[dst]);
|
if (remove(buffer[dst]) != 0) {
|
||||||
|
if (errno != ENOENT) {
|
||||||
|
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (maxindex > 0) {
|
while (maxindex > 0) {
|
||||||
int src = 1 - dst;
|
int src = 1 - dst;
|
||||||
sprintf(buffer[src], "%s.%d", filename, --maxindex);
|
sprintf(buffer[src], "%s.%d", filename, --maxindex);
|
||||||
err = rename(buffer[src], buffer[dst]);
|
if (rename(buffer[src], buffer[dst]) != 0) {
|
||||||
if ((err != 0) && (err != ENOENT)) {
|
if (errno != ENOENT) {
|
||||||
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
}
|
}
|
||||||
dst = src;
|
dst = src;
|
||||||
}
|
}
|
||||||
err = rename(filename, buffer[dst]);
|
if (rename(filename, buffer[dst]) != 0) {
|
||||||
if ((err != 0) && (err != ENOENT)) {
|
if (errno != ENOENT) {
|
||||||
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue