From c7209f051c44912da2e367e984a8c8660b9139d2 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 5 Oct 2004 01:44:23 +0000 Subject: [PATCH] * Changed a bunch of localtime() calls to localtime_r(), for great justice. --- citadel/ChangeLog | 4 +- citadel/citadel.c | 10 +- citadel/citserver.c | 8 +- citadel/commands.c | 30 +++--- citadel/genstamp.c | 32 +++--- citadel/imap_misc.c | 18 ++-- citadel/imap_tools.c | 2 +- citadel/msgform.c | 222 +++++++++++++++++++++++++----------------- citadel/serv_expire.c | 2 +- citadel/sysdep.c | 28 +++--- citadel/tools.c | 28 +++--- citadel/userlist.c | 10 +- 12 files changed, 220 insertions(+), 174 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index ba00e3a41..9318267c2 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 626.7 2004/10/05 01:44:20 ajc + * Changed a bunch of localtime() calls to localtime_r(), for great justice. + Revision 626.6 2004/10/04 21:40:29 error * configure.ac: Add CFLAGS for icc Intel Compiler @@ -6141,4 +6144,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/citadel.c b/citadel/citadel.c index 3915d8eb1..7c09e40e2 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -206,7 +206,7 @@ void userlist(CtdlIPC *ipc, char *patn) { char buf[SIZ]; char fl[SIZ]; - struct tm *tmbuf; + struct tm tmbuf; time_t lc; int r; /* IPC response code */ char *listing = NULL; @@ -230,11 +230,11 @@ void userlist(CtdlIPC *ipc, char *patn) pprintf("%5ld %d ", extract_long(buf, 2), extract_int(buf, 1)); lc = extract_long(buf, 3); - tmbuf = (struct tm *) localtime(&lc); + localtime_r(&lc, &tmbuf); pprintf("%02d/%02d/%04d ", - (tmbuf->tm_mon + 1), - tmbuf->tm_mday, - (tmbuf->tm_year + 1900)); + (tmbuf.tm_mon + 1), + tmbuf.tm_mday, + (tmbuf.tm_year + 1900)); pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5)); } diff --git a/citadel/citserver.c b/citadel/citserver.c index 82e58d988..dcd1045d4 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -376,16 +376,16 @@ char CtdlCheckExpress(void) { void cmd_time(void) { time_t tv; - struct tm *tmp; + struct tm tmp; tv = time(NULL); - tmp = localtime(&tv); + localtime_r(&tv, &tmp); /* timezone and daylight global variables are not portable. */ #ifdef HAVE_STRUCT_TM_TM_GMTOFF - cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp->tm_gmtoff, tmp->tm_isdst); + cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst); #else - cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp->tm_isdst); + cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst); #endif } diff --git a/citadel/commands.c b/citadel/commands.c index ea3e527cb..758df4aa0 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -206,7 +206,7 @@ void print_instant(void) char buf[1024]; FILE *outpipe; time_t timestamp; - struct tm *stamp; + struct tm stamp; int flags = 0; char sender[64]; char node[64]; @@ -236,7 +236,7 @@ void print_instant(void) extract(node, buf, 4); strcpy(last_paged, sender); - stamp = localtime(×tamp); + localtime_r(×tamp, &stamp); /* If the page is a Logoff Request, honor it. */ if (flags & 2) { @@ -258,17 +258,17 @@ void print_instant(void) else fprintf(outpipe, "Message "); /* Timestamp. Can this be improved? */ - if (stamp->tm_hour == 0 || stamp->tm_hour == 12) + if (stamp.tm_hour == 0 || stamp.tm_hour == 12) fprintf(outpipe, "at 12:%02d%cm", - stamp->tm_min, - stamp->tm_hour ? 'p' : 'a'); - else if (stamp->tm_hour > 12) /* pm */ + stamp.tm_min, + stamp.tm_hour ? 'p' : 'a'); + else if (stamp.tm_hour > 12) /* pm */ fprintf(outpipe, "at %d:%02dpm", - stamp->tm_hour - 12, - stamp->tm_min); + stamp.tm_hour - 12, + stamp.tm_min); else /* am */ fprintf(outpipe, "at %d:%02dam", - stamp->tm_hour, stamp->tm_min); + stamp.tm_hour, stamp.tm_min); fprintf(outpipe, " from %s", sender); if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32)) fprintf(outpipe, " @%s", node); @@ -294,14 +294,14 @@ void print_instant(void) scr_printf("Message "); /* Timestamp. Can this be improved? */ - if (stamp->tm_hour == 0 || stamp->tm_hour == 12)/* 12am/12pm */ - scr_printf("at 12:%02d%cm", stamp->tm_min, - stamp->tm_hour ? 'p' : 'a'); - else if (stamp->tm_hour > 12) /* pm */ + if (stamp.tm_hour == 0 || stamp.tm_hour == 12)/* 12am/12pm */ + scr_printf("at 12:%02d%cm", stamp.tm_min, + stamp.tm_hour ? 'p' : 'a'); + else if (stamp.tm_hour > 12) /* pm */ scr_printf("at %d:%02dpm", - stamp->tm_hour - 12, stamp->tm_min); + stamp.tm_hour - 12, stamp.tm_min); else /* am */ - scr_printf("at %d:%02dam", stamp->tm_hour, stamp->tm_min); + scr_printf("at %d:%02dam", stamp.tm_hour, stamp.tm_min); /* Sender */ scr_printf(" from %s", sender); diff --git a/citadel/genstamp.c b/citadel/genstamp.c index 09fe19469..e97fb9796 100644 --- a/citadel/genstamp.c +++ b/citadel/genstamp.c @@ -44,16 +44,16 @@ static char *weekdays[] = { * time and date stamp. */ void datestring(char *buf, size_t n, time_t xtime, int which_format) { - struct tm *t; + struct tm t; long offset; char offsign; - t = localtime(&xtime); + localtime_r(&xtime, &t); /* Convert "seconds west of GMT" to "hours/minutes offset" */ #ifdef HAVE_STRUCT_TM_TM_GMTOFF - offset = t->tm_gmtoff; + offset = t.tm_gmtoff; #else offset = timezone; #endif @@ -70,25 +70,25 @@ void datestring(char *buf, size_t n, time_t xtime, int which_format) { case DATESTRING_RFC822: snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld", - weekdays[t->tm_wday], - t->tm_mday, - months[t->tm_mon], - t->tm_year + 1900, - t->tm_hour, - t->tm_min, - t->tm_sec, + weekdays[t.tm_wday], + t.tm_mday, + months[t.tm_mon], + t.tm_year + 1900, + t.tm_hour, + t.tm_min, + t.tm_sec, offsign, offset ); break; case DATESTRING_IMAP: snprintf(buf, n, "%02d-%s-%04d %02d:%02d:%02d %c%04ld", - t->tm_mday, - months[t->tm_mon], - t->tm_year + 1900, - t->tm_hour, - t->tm_min, - t->tm_sec, + t.tm_mday, + months[t.tm_mon], + t.tm_year + 1900, + t.tm_hour, + t.tm_min, + t.tm_sec, offsign, offset ); break; diff --git a/citadel/imap_misc.c b/citadel/imap_misc.c index 36ae353f8..b4299c583 100644 --- a/citadel/imap_misc.c +++ b/citadel/imap_misc.c @@ -143,7 +143,7 @@ void imap_print_instant_messages(void) { char tmp[SIZ]; int i; size_t size, size2; - struct tm *stamp; + struct tm stamp; if (CC->FirstExpressMessage == NULL) { return; @@ -154,7 +154,7 @@ void imap_print_instant_messages(void) { end_critical_section(S_SESSION_TABLE); while (ptr != NULL) { - stamp = localtime(&(ptr->timestamp)); + localtime_r(&(ptr->timestamp), &stamp); size = strlen(ptr->text) + SIZ; dumpomatic = malloc(size); strcpy(dumpomatic, ""); @@ -168,17 +168,17 @@ void imap_print_instant_messages(void) { strcat(dumpomatic, "Message "); /* Timestamp. Can this be improved? */ - if (stamp->tm_hour == 0 || stamp->tm_hour == 12) + if (stamp.tm_hour == 0 || stamp.tm_hour == 12) sprintf(tmp, "at 12:%02d%cm", - stamp->tm_min, - stamp->tm_hour ? 'p' : 'a'); - else if (stamp->tm_hour > 12) /* pm */ + stamp.tm_min, + stamp.tm_hour ? 'p' : 'a'); + else if (stamp.tm_hour > 12) /* pm */ sprintf(tmp, "at %d:%02dpm", - stamp->tm_hour - 12, - stamp->tm_min); + stamp.tm_hour - 12, + stamp.tm_min); else /* am */ sprintf(tmp, "at %d:%02dam", - stamp->tm_hour, stamp->tm_min); + stamp.tm_hour, stamp.tm_min); strcat(dumpomatic, tmp); size2 = strlen(dumpomatic); diff --git a/citadel/imap_tools.c b/citadel/imap_tools.c index 597e50a6c..d1f2654fe 100644 --- a/citadel/imap_tools.c +++ b/citadel/imap_tools.c @@ -415,7 +415,7 @@ int imap_datecmp(char *datestr, time_t msgtime) { } /* Extract day/month/year from message timestamp */ - memcpy(&msgtm, localtime(&msgtime), sizeof(struct tm)); + localtime_r(&msgtime, &msgtm); msgday = msgtm.tm_mday; msgmonth = msgtm.tm_mon; msgyear = msgtm.tm_year + 1900; diff --git a/citadel/msgform.c b/citadel/msgform.c index ba6f2fdfc..16df9aeb7 100644 --- a/citadel/msgform.c +++ b/citadel/msgform.c @@ -6,8 +6,8 @@ * * If the -q (quiet or qwk) flag is used, only the message text prints, and * then it stops at the end of the first message it prints. - * This is used by the QWK reader for Citadel during message format - * translation. + * + * This utility isn't very useful anymore. * */ @@ -35,8 +35,8 @@ int qwk = 0; -int fpgetfield(FILE *fp, char *string); -int fmout(int width, FILE *fp); +int fpgetfield(FILE * fp, char *string); +int fmout(int width, FILE * fp); #ifndef HAVE_STRERROR @@ -47,121 +47,165 @@ char *strerror(int e) { static char buf[32]; - snprintf(buf, sizeof buf, "errno = %d",e); - return(buf); - } + snprintf(buf, sizeof buf, "errno = %d", e); + return (buf); +} #endif int main(int argc, char **argv) { - struct tm *tm; - int a,b,e,mtype,aflag; + struct tm tm; + int a, b, e, mtype, aflag; char bbb[1024]; char subject[1024]; FILE *fp; time_t now; - if (argc==2) if (!strcmp(argv[1],"-q")) qwk = 1; - fp=stdin; - if (argc==2) if (strcmp(argv[1],"-q")) { - fp = fopen(argv[1],"r"); - if (fp==NULL) { - fprintf(stderr,"%s: cannot open %s: %s\n", - argv[0],argv[1],strerror(errno)); - exit(errno); + if (argc == 2) + if (!strcmp(argv[1], "-q")) + qwk = 1; + fp = stdin; + if (argc == 2) + if (strcmp(argv[1], "-q")) { + fp = fopen(argv[1], "r"); + if (fp == NULL) { + fprintf(stderr, "%s: cannot open %s: %s\n", + argv[0], argv[1], strerror(errno)); + exit(errno); } } TOP: do { - e=getc(fp); - if (e<0) exit(0); - } while(e!=255); - strcpy(subject,""); - mtype=getc(fp); aflag=getc(fp); - if (qwk == 0) printf(" "); - - do { - b=getc(fp); - if (b=='M') { - if (qwk==0) { + e = getc(fp); + if (e < 0) + exit(0); + } while (e != 255); + strcpy(subject, ""); + mtype = getc(fp); + aflag = getc(fp); + if (qwk == 0) + printf(" "); + + do { + b = getc(fp); + if (b == 'M') { + if (qwk == 0) { printf("\n"); - if (strlen(subject)!=0) - printf("Subject: %s\n",subject); - } - if (aflag!=1) fmout(80,fp); - else while(a=getc(fp), a>0) { - if (a==13) putc(10,stdout); - else putc(a,stdout); + if (strlen(subject) != 0) + printf("Subject: %s\n", subject); } + if (aflag != 1) + fmout(80, fp); + else + while (a = getc(fp), a > 0) { + if (a == 13) + putc(10, stdout); + else + putc(a, stdout); + } } - if ((b!='M')&&(b>0)) fpgetfield(fp,bbb); - if (b=='U') strcpy(subject,bbb); - if (qwk==0) { - if (b=='A') printf("from %s ",bbb); - if (b=='N') printf("@%s ",bbb); - if (b=='O') printf("in %s> ",bbb); - if (b=='R') printf("to %s ",bbb); - if (b=='T') { - now=atol(bbb); - tm=(struct tm *)localtime(&now); - strcpy(bbb,asctime(tm)); bbb[strlen(bbb)-1]=0; - printf("%s ",&bbb[4]); + if ((b != 'M') && (b > 0)) + fpgetfield(fp, bbb); + if (b == 'U') + strcpy(subject, bbb); + if (qwk == 0) { + if (b == 'A') + printf("from %s ", bbb); + if (b == 'N') + printf("@%s ", bbb); + if (b == 'O') + printf("in %s> ", bbb); + if (b == 'R') + printf("to %s ", bbb); + if (b == 'T') { + now = atol(bbb); + localtime_r(&now, &tm); + strcpy(bbb, asctime(&tm)); + bbb[strlen(bbb) - 1] = 0; + printf("%s ", &bbb[4]); } } - } while ((b!='M')&&(b>0)); - if (qwk==0) printf("\n"); - if (qwk==1) exit(0); + } while ((b != 'M') && (b > 0)); + if (qwk == 0) + printf("\n"); + if (qwk == 1) + exit(0); goto TOP; } -int fpgetfield(FILE *fp, char *string) /* level-2 break out next null-terminated string */ - - -{ -int a,b; -strcpy(string,""); -a=0; +int fpgetfield(FILE * fp, char *string) + +{ /* level-2 break out next null-terminated string */ + int a, b; + strcpy(string, ""); + a = 0; do { - b=getc(fp); - if (b<1) { string[a]=0; return(0); } - string[a]=b; + b = getc(fp); + if (b < 1) { + string[a] = 0; + return (0); + } + string[a] = b; ++a; - } while(b!=0); - return(0); + } while (b != 0); + return (0); } -int fmout(int width, FILE *fp) +int fmout(int width, FILE * fp) { - int a,b,c; + int a, b, c; int real = 0; int old = 0; char aaa[140]; - - strcpy(aaa,""); old=255; - c=1; /* c is the current pos */ -FMTA: old=real; a=getc(fp); real=a; - if (a<=0) goto FMTEND; - - if ( ((a==13)||(a==10)) && (old!=13) && (old!=10) ) a=32; - if ( ((old==13)||(old==10)) && (isspace(real)) ) { - printf("\n"); c=1; } - if (a>126) goto FMTA; - - if (a>32) { - if ( ((strlen(aaa)+c)>(width-5)) && (strlen(aaa)>(width-5)) ) - { printf("\n%s",aaa); c=strlen(aaa); aaa[0]=0; } - b=strlen(aaa); aaa[b]=a; aaa[b+1]=0; } - if (a==32) { if ((strlen(aaa)+c)>(width-5)) { - printf("\n"); - c=1; - } - printf("%s ",aaa); ++c; c=c+strlen(aaa); - strcpy(aaa,""); goto FMTA; } - if ((a==13)||(a==10)) { - printf("%s\n",aaa); c=1; - strcpy(aaa,""); goto FMTA; } + + strcpy(aaa, ""); + old = 255; + c = 1; /* c is the current pos */ +FMTA: old = real; + a = getc(fp); + real = a; + if (a <= 0) + goto FMTEND; + + if (((a == 13) || (a == 10)) && (old != 13) && (old != 10)) + a = 32; + if (((old == 13) || (old == 10)) && (isspace(real))) { + printf("\n"); + c = 1; + } + if (a > 126) + goto FMTA; + + if (a > 32) { + if (((strlen(aaa) + c) > (width - 5)) + && (strlen(aaa) > (width - 5))) { + printf("\n%s", aaa); + c = strlen(aaa); + aaa[0] = 0; + } + b = strlen(aaa); + aaa[b] = a; + aaa[b + 1] = 0; + } + if (a == 32) { + if ((strlen(aaa) + c) > (width - 5)) { + printf("\n"); + c = 1; + } + printf("%s ", aaa); + ++c; + c = c + strlen(aaa); + strcpy(aaa, ""); + goto FMTA; + } + if ((a == 13) || (a == 10)) { + printf("%s\n", aaa); + c = 1; + strcpy(aaa, ""); + goto FMTA; + } goto FMTA; FMTEND: printf("\n"); - return(0); + return (0); } diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index 80e4ea202..2ee22eae2 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -632,7 +632,7 @@ void purge_databases(void) { * last twelve hours. This is usually enough granularity. */ now = time(NULL); - memcpy(&tm, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &tm); if (tm.tm_hour != config.c_purge_hour) return; if ((now - last_purge) < 43200) return; diff --git a/citadel/sysdep.c b/citadel/sysdep.c index ce1a9dcad..21722e173 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -126,13 +126,13 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { } else if (loglevel <= verbosity) { struct timeval tv; - struct tm *tim; + struct tm tim; time_t unixtime; gettimeofday(&tv, NULL); /* Promote to time_t; types differ on some OSes (like darwin) */ unixtime = tv.tv_sec; - tim = localtime(&unixtime); + localtime_r(&unixtime, &tim); /* * Log provides millisecond accuracy. If you need * microsecond accuracy and your OS supports it, change @@ -143,33 +143,33 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { /* Millisecond display */ fprintf(stderr, "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%3d] %s", - tim->tm_year + 1900, tim->tm_mon + 1, - tim->tm_mday, tim->tm_hour, tim->tm_min, - tim->tm_sec, (long)tv.tv_usec / 1000, + tim.tm_year + 1900, tim.tm_mon + 1, + tim.tm_mday, tim.tm_hour, tim.tm_min, + tim.tm_sec, (long)tv.tv_usec / 1000, CC->cs_pid, buf); #endif /* Microsecond display */ fprintf(stderr, "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] %s", - tim->tm_year + 1900, tim->tm_mon + 1, - tim->tm_mday, tim->tm_hour, tim->tm_min, - tim->tm_sec, (long)tv.tv_usec, + tim.tm_year + 1900, tim.tm_mon + 1, + tim.tm_mday, tim.tm_hour, tim.tm_min, + tim.tm_sec, (long)tv.tv_usec, CC->cs_pid, buf); } else { #if 0 /* Millisecond display */ fprintf(stderr, "%04d/%02d/%02d %2d:%02d:%02d.%03ld %s", - tim->tm_year + 1900, tim->tm_mon + 1, - tim->tm_mday, tim->tm_hour, tim->tm_min, - tim->tm_sec, (long)tv.tv_usec / 1000, buf); + tim.tm_year + 1900, tim.tm_mon + 1, + tim.tm_mday, tim.tm_hour, tim.tm_min, + tim.tm_sec, (long)tv.tv_usec / 1000, buf); #endif /* Microsecond display */ fprintf(stderr, "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s", - tim->tm_year + 1900, tim->tm_mon + 1, - tim->tm_mday, tim->tm_hour, tim->tm_min, - tim->tm_sec, (long)tv.tv_usec, buf); + tim.tm_year + 1900, tim.tm_mon + 1, + tim.tm_mday, tim.tm_hour, tim.tm_min, + tim.tm_sec, (long)tv.tv_usec, buf); } fflush(stderr); } diff --git a/citadel/tools.c b/citadel/tools.c index 17fcb225d..3d980eaaf 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -366,34 +366,34 @@ int haschar(const char *st, int ch) * seconds is whether to print the seconds */ void fmt_date(char *buf, size_t n, time_t thetime, int seconds) { - struct tm *tm; + struct tm tm; int hour; strcpy(buf, ""); - tm = localtime(&thetime); + localtime_r(&thetime, &tm); - hour = tm->tm_hour; + hour = tm.tm_hour; if (hour == 0) hour = 12; else if (hour > 12) hour = hour - 12; if (seconds) { snprintf(buf, n, "%s %d %4d %d:%02d:%02d%s", - ascmonths[tm->tm_mon], - tm->tm_mday, - tm->tm_year + 1900, + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900, hour, - tm->tm_min, - tm->tm_sec, - ( (tm->tm_hour >= 12) ? "pm" : "am" ) + tm.tm_min, + tm.tm_sec, + ( (tm.tm_hour >= 12) ? "pm" : "am" ) ); } else { snprintf(buf, n, "%s %d %4d %d:%02d%s", - ascmonths[tm->tm_mon], - tm->tm_mday, - tm->tm_year + 1900, + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900, hour, - tm->tm_min, - ( (tm->tm_hour >= 12) ? "pm" : "am" ) + tm.tm_min, + ( (tm.tm_hour >= 12) ? "pm" : "am" ) ); } } diff --git a/citadel/userlist.c b/citadel/userlist.c index 9c23f1891..00534037d 100644 --- a/citadel/userlist.c +++ b/citadel/userlist.c @@ -34,7 +34,7 @@ void logoff(int code) void userlist(CtdlIPC *ipc) { char buf[SIZ]; char fl[SIZ]; - struct tm *tmbuf; + struct tm tmbuf; time_t lc; char *listing = NULL; int r; @@ -54,11 +54,11 @@ void userlist(CtdlIPC *ipc) { printf("%5ld %d ",extract_long(buf,2), extract_int(buf,1)); lc = extract_long(buf,3); - tmbuf = (struct tm *)localtime(&lc); + localtime_r(&lc, &tmbuf); printf("%02d/%02d/%04d ", - (tmbuf->tm_mon+1), - tmbuf->tm_mday, - (tmbuf->tm_year + 1900)); + (tmbuf.tm_mon+1), + tmbuf.tm_mday, + (tmbuf.tm_year + 1900)); printf("%5ld %5ld\n", extract_long(buf,4),extract_long(buf,5)); } -- 2.30.2