$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
{
char buf[SIZ];
char fl[SIZ];
- struct tm *tmbuf;
+ struct tm tmbuf;
time_t lc;
int r; /* IPC response code */
char *listing = NULL;
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));
}
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
}
char buf[1024];
FILE *outpipe;
time_t timestamp;
- struct tm *stamp;
+ struct tm stamp;
int flags = 0;
char sender[64];
char node[64];
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) {
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);
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);
* 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
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;
char tmp[SIZ];
int i;
size_t size, size2;
- struct tm *stamp;
+ struct tm stamp;
if (CC->FirstExpressMessage == NULL) {
return;
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, "");
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);
}
/* 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;
*
* 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.
*
*/
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
{
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);
}
* 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;
}
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
/* 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);
}
* 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" )
);
}
}
void userlist(CtdlIPC *ipc) {
char buf[SIZ];
char fl[SIZ];
- struct tm *tmbuf;
+ struct tm tmbuf;
time_t lc;
char *listing = NULL;
int r;
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));
}