/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
struct stat sb;
#endif
- char from[MAXPATHLEN];
- char to[MAXPATHLEN];
l_stdio_t *ll = (l_stdio_t *) lf->data;
const char *realpath = lf->path+6; // skip 'stdio:' prefix.
assert(realpath);
debugs(0, DBG_IMPORTANT, "Rotate log file " << lf->path);
+ SBuf basePath(realpath);
+
/* Rotate numbers 0 through N up one */
for (int16_t i = nRotate; i > 1;) {
--i;
- snprintf(from, MAXPATHLEN, "%s.%d", realpath, i - 1);
- snprintf(to, MAXPATHLEN, "%s.%d", realpath, i);
- xrename(from, to);
+ SBuf from(basePath);
+ from.appendf(".%d", i-1);
+ SBuf to(basePath);
+ to.appendf(".%d", i);
+ FileRename(from, to);
+ // TODO handle rename errors
}
/* Rotate the current log to .0 */
file_close(ll->fd); /* always close */
if (nRotate > 0) {
- snprintf(to, MAXPATHLEN, "%s.%d", realpath, 0);
- xrename(realpath, to);
+ SBuf to(basePath);
+ to.appendf(".0");
+ FileRename(basePath, to);
+ // TODO handle rename errors
}
/* Reopen the log. It may have been renamed "manually" */
ll->fd = file_open(realpath, O_WRONLY | O_CREAT | O_TEXT);