93 |
{ |
{ |
94 |
#ifdef HAVE_SYSLOG_H |
#ifdef HAVE_SYSLOG_H |
95 |
case SYSLOG: |
case SYSLOG: |
96 |
syslog (severity, buf); |
syslog (severity, "%s", buf); |
97 |
break; |
break; |
98 |
#endif |
#endif |
99 |
case MAIL: |
case MAIL: |
570 |
return strftime (s, size, template, brokentime); |
return strftime (s, size, template, brokentime); |
571 |
else |
else |
572 |
{ |
{ |
573 |
const int FORMAT_PADDING = 30; /* 3 extra chars for each %z */ |
int padding = 0; |
|
char *fixed_template = (char*)xmalloc (strlen(template)+FORMAT_PADDING); |
|
574 |
const char *in = template; |
const char *in = template; |
575 |
char *out = fixed_template; |
char *fixed_template = 0; |
576 |
|
char *out = 0; |
577 |
/* Because brokentime points to static data (allocated |
/* Because brokentime points to static data (allocated |
578 |
* by localtime()), it cannot be passed to a subroutine |
* by localtime()), it cannot be passed to a subroutine |
579 |
* and then later be relied on to point to the same data. */ |
* and then later be relied on to point to the same data. */ |
580 |
struct tm btime = *brokentime; |
struct tm btime = *brokentime; |
581 |
int result; |
int result; |
582 |
|
|
583 |
|
/* Count number of %z so we know how much characters to add to the |
584 |
|
* template. We actually count the number of additional characters. |
585 |
|
* As we are going to replace each "%z" by "+hhmm" (sign, hours, |
586 |
|
* minutes), this is 3 extra chars for each %z. */ |
587 |
|
while (*in) |
588 |
|
{ |
589 |
|
if (*in == '%' && *(in+1) == 'z') |
590 |
|
{ |
591 |
|
in += 2; |
592 |
|
padding += 3; /* 3 extra chars for each %z */ |
593 |
|
} |
594 |
|
else |
595 |
|
{ |
596 |
|
in++; |
597 |
|
} |
598 |
|
} |
599 |
|
|
600 |
|
/* Now allocate enough space. */ |
601 |
|
fixed_template = (char*)xmalloc (strlen(template)+padding+1); |
602 |
|
in = template; /* Inspect it again, this time replacing all %z. */ |
603 |
|
out = fixed_template; |
604 |
|
|
605 |
while (*in != '\0') |
while (*in != '\0') |
606 |
{ |
{ |