Skip to content

Commit 8efbe7a

Browse files
author
Michael Ortmann
committed
Merge remote-tracking branch 'origin/localtime_r' into develop
2 parents 322bddb + 7085082 commit 8efbe7a

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

src/main.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static int nested_debug = 0;
254254
static void write_debug()
255255
{
256256
int x;
257-
char s[25];
257+
char s[26];
258258
int y;
259259

260260
if (nested_debug) {
@@ -267,8 +267,8 @@ static void write_debug()
267267
x = creat("DEBUG.DEBUG", 0644);
268268
if (x >= 0) {
269269
setsock(x, SOCK_NONSOCK);
270-
strlcpy(s, ctime(&now), sizeof s);
271-
dprintf(-x, "Debug (%s) written %s\n", ver, s);
270+
ctime_r(&now, s);
271+
dprintf(-x, "Debug (%s) written %s", ver, s);
272272
dprintf(-x, "Please report problem to https://github.com/eggheads/eggdrop/issues\n");
273273
#ifdef EGG_PATCH
274274
dprintf(-x, "Patch level: %s\n", EGG_PATCH);
@@ -297,8 +297,8 @@ static void write_debug()
297297
if (x < 0) {
298298
putlog(LOG_MISC, "*", "* Failed to write DEBUG");
299299
} else {
300-
strlcpy(s, ctime(&now), sizeof s);
301-
dprintf(-x, "Debug (%s) written %s\n", ver, s);
300+
ctime_r(&now, s);
301+
dprintf(-x, "Debug (%s) written %s", ver, s);
302302
#ifdef EGG_PATCH
303303
dprintf(-x, "Patch level: %s\n", EGG_PATCH);
304304
#else
@@ -633,7 +633,7 @@ static void core_secondly()
633633
}
634634
nowmins = time(NULL) / 60;
635635
if (nowmins > lastmin) {
636-
memcpy(&nowtm, localtime(&now), sizeof(struct tm));
636+
localtime_r(&now, &nowtm);
637637
i = 0;
638638

639639
/* Once a minute */
@@ -661,10 +661,11 @@ static void core_secondly()
661661
check_logsize();
662662
}
663663
if (!miltime) { /* At midnight */
664-
char s[25];
664+
char s[26];
665665
int j;
666666

667-
strlcpy(s, ctime(&now), sizeof s);
667+
ctime_r(&now, s);
668+
s[24] = 0;
668669
if (quiet_save < 3)
669670
putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
670671
call_hook(HOOK_BACKUP);
@@ -1002,7 +1003,7 @@ static void init_random(void) {
10021003
int main(int arg_c, char **arg_v)
10031004
{
10041005
int i, xx;
1005-
char s[25];
1006+
char s[26];
10061007
FILE *f;
10071008
struct sigaction sv;
10081009
struct chanset_t *chan;
@@ -1124,8 +1125,8 @@ int main(int arg_c, char **arg_v)
11241125
dns_thread_head = nmalloc(sizeof(struct dns_thread_node));
11251126
dns_thread_head->next = NULL;
11261127
#endif
1127-
strlcpy(s, ctime(&now), sizeof s);
1128-
memmove(&s[11], &s[20], strlen(&s[20]) + 1);
1128+
ctime_r(&now, s);
1129+
s[24] = 0;
11291130
putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s);
11301131
chanprog();
11311132
if (!encrypt_pass2 && !encrypt_pass) {

src/misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,18 @@ void putlog (int type, char *chname, const char *format, ...)
518518
va_list va;
519519
time_t now2 = time(NULL);
520520
static time_t now2_last = 0; /* cache expensive localtime() */
521-
static struct tm *t;
521+
static struct tm t;
522522

523523
if (now2 != now2_last) {
524524
now2_last = now2;
525-
t = localtime(&now2);
525+
localtime_r(&now2, &t);
526526
}
527527

528528
va_start(va, format);
529529

530530
/* Create the timestamp */
531531
if (shtime) {
532-
strftime(stamp, sizeof(stamp) - 2, log_ts, t);
532+
strftime(stamp, sizeof(stamp) - 2, log_ts, &t);
533533
strcat(stamp, " ");
534534
tsl = strlen(stamp);
535535
}
@@ -545,9 +545,9 @@ void putlog (int type, char *chname, const char *format, ...)
545545
out[LOGLINEMAX - tsl] = 0;
546546
if (keep_all_logs) {
547547
if (!logfile_suffix[0])
548-
strftime(ct, 12, ".%d%b%Y", t);
548+
strftime(ct, 12, ".%d%b%Y", &t);
549549
else {
550-
strftime(ct, 80, logfile_suffix, t);
550+
strftime(ct, 80, logfile_suffix, &t);
551551
ct[80] = 0;
552552
s2 = ct;
553553
/* replace spaces by underscores */

src/mod/channels.mod/channels.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static char *convert_element(char *src, char *dst)
385385
static void write_channels()
386386
{
387387
FILE *f;
388-
char s[sizeof chanfile + 4], w[1024], w2[1024], name[163];
388+
char s[sizeof chanfile + 4], s1[26], w[1024], w2[1024], name[163];
389389
char need1[242], need2[242], need3[242], need4[242], need5[242];
390390
struct chanset_t *chan;
391391
struct udef_struct *ul;
@@ -401,8 +401,9 @@ static void write_channels()
401401
}
402402
if (!quiet_save)
403403
putlog(LOG_MISC, "*", "Writing channel file...");
404-
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s\n",
405-
botnetnick, ver, ctime(&now));
404+
ctime_r(&now, s1);
405+
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s",
406+
botnetnick, ver, s1);
406407
for (chan = chanset; chan; chan = chan->next) {
407408
convert_element(chan->dname, name);
408409
get_mode_protect(chan, w);

src/mod/ctcp.mod/ctcp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ static int ctcp_CLIENTINFO(char *nick, char *uhosr, char *handle,
128128
static int ctcp_TIME(char *nick, char *uhost, char *handle, char *object,
129129
char *keyword, char *text)
130130
{
131-
char tms[25];
131+
char s[26];
132132

133133
if (ctcp_mode == 1)
134134
return 1;
135-
strlcpy(tms, ctime(&now), sizeof tms);
136-
simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, tms);
135+
ctime_r(&now, s);
136+
s[24] = 0;
137+
sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, s);
137138
return 1;
138139
}
139140

src/mod/uptime.mod/uptime.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ static int uptime_expmem()
9696
static void uptime_report(int idx, int details)
9797
{
9898
int delta_seconds;
99-
char *next_update_at;
99+
char next_update_at[26];
100100

101101
if (details) {
102102
delta_seconds = (int) (next_update - time(NULL));
103-
next_update_at = ctime(&next_update);
104-
next_update_at[strlen(next_update_at) - 1] = 0;
105-
103+
ctime_r(&next_update, next_update_at);
104+
next_update_at[24] = 0;
106105
dprintf(idx, " %d uptime packet%s sent\n", uptimecount,
107106
(uptimecount != 1) ? "s" : "");
108107
dprintf(idx, " Approximately %-.2f hours until next update "

src/tclmisc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,13 @@ static int tcl_unixtime STDVAR
413413
static int tcl_ctime STDVAR
414414
{
415415
time_t tt;
416-
char s[25];
416+
char s[26];
417417

418418
BADARGS(2, 2, " unixtime");
419419

420420
tt = (time_t) atol(argv[1]);
421-
strlcpy(s, ctime(&tt), sizeof s);
421+
ctime_r(&tt, s);
422+
s[24] = 0;
422423
Tcl_AppendResult(irp, s, NULL);
423424
return TCL_OK;
424425
}

src/userrec.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ void write_userfile(int idx)
567567
{
568568
FILE *f;
569569
char new_userfile[(sizeof userfile) + 4]; /* 4 = strlen("~new") */
570-
char s1[81];
571-
time_t tt;
570+
char s[26];
572571
struct userrec *u;
573572
int ok;
574573

@@ -587,9 +586,8 @@ void write_userfile(int idx)
587586
putlog(LOG_MISC, "*", "%s", USERF_WRITING);
588587

589588
sort_userlist();
590-
tt = now;
591-
strlcpy(s1, ctime(&tt), sizeof s1);
592-
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s1);
589+
ctime_r(&now, s);
590+
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s);
593591
ok = 1;
594592
/* Add all users except the -tn user */
595593
for (u = userlist; u && ok; u = u->next)

0 commit comments

Comments
 (0)