1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-01 23:26:37 +02:00

Add function pretty_time_val_r(), for which you can specify a buf.

This commit is contained in:
Bram Matthys
2021-12-26 08:59:44 +01:00
parent 7f9c7a0eb4
commit d687e310bd
2 changed files with 12 additions and 7 deletions
+1
View File
@@ -315,6 +315,7 @@ extern const char *myctime(time_t);
extern const char *short_date(time_t, char *buf);
extern const char *long_date(time_t);
extern const char *pretty_time_val(long);
extern const char *pretty_time_val_r(char *buf, size_t buflen, long timeval);
extern const char *pretty_date(time_t t);
extern time_t server_time_to_unix_time(const char *tbuf);
extern time_t rfc2616_time_to_unix_time(const char *tbuf);
+11 -7
View File
@@ -3107,27 +3107,31 @@ void init_dynconf(void)
memset(&tempiConf, 0, sizeof(iConf));
}
const char *pretty_time_val(long timeval)
const char *pretty_time_val_r(char *buf, size_t buflen, long timeval)
{
static char buf[512];
if (timeval == 0)
return "0";
buf[0] = 0;
if (timeval/86400)
snprintf(buf, sizeof(buf), "%ldd", timeval/86400);
snprintf(buf, buflen, "%ldd", timeval/86400);
if ((timeval/3600) % 24)
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%ldh", (timeval/3600)%24);
snprintf(buf+strlen(buf), buflen-strlen(buf), "%ldh", (timeval/3600)%24);
if ((timeval/60)%60)
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%ldm", (timeval/60)%60);
snprintf(buf+strlen(buf), buflen-strlen(buf), "%ldm", (timeval/60)%60);
if ((timeval%60))
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%lds", timeval%60);
snprintf(buf+strlen(buf), buflen-strlen(buf), "%lds", timeval%60);
return buf;
}
const char *pretty_time_val(long timeval)
{
static char buf[512];
return pretty_time_val_r(buf, sizeof(buf), timeval);
}
/* This converts a relative path to an absolute path, but only if necessary. */
void convert_to_absolute_path(char **path, const char *reldir)
{