Skip to content

Commit f0cf7ae

Browse files
cosmo0920edsiper
authored andcommitted
strptime: Use detected results of the existence of tm_zone member
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent c9e3b5a commit f0cf7ae

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

include/fluent-bit/flb_time.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct flb_time {
3232

3333
struct flb_tm {
3434
struct tm tm;
35-
#ifdef FLB_HAVE_TIME_ZONE
35+
#ifndef FLB_HAVE_TIME_ZONE
3636
char *tm_zone;
3737
#endif
3838
#ifndef FLB_HAVE_GMTOFF
@@ -46,6 +46,12 @@ struct flb_tm {
4646
#define flb_tm_gmtoff(x) (x)->tm.tm_gmtoff
4747
#endif
4848

49+
#ifndef FLB_HAVE_TIME_ZONE
50+
#define flb_tm_zone(x) (x)->tm_zone
51+
#else
52+
#define flb_tm_zone(x) (x)->tm.tm_zone
53+
#endif
54+
4955
/*
5056
to represent eventtime of fluentd
5157
see also

src/flb_strptime.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,13 @@ again: switch (c = *fmt++) {
519519
return (NULL);
520520
flb_tm_gmtoff(tm) = 0;
521521
tm->tm.tm_isdst = 0;
522-
#ifdef FLB_HAVE_TIME_ZONE
523-
tm->tm_zone = "UTC";
522+
flb_tm_zone(tm) = "UTC";
524523
for(i=0; flb_known_timezones[i].abbr != NULL; ++i) { /* Prefer "UTC" from list if available */
525524
if (strcmp(flb_known_timezones[i].abbr, "UTC") == 0) {
526-
tm->tm_zone = flb_known_timezones[i].abbr;
525+
flb_tm_zone(tm) = flb_known_timezones[i].abbr;
527526
break;
528527
}
529528
}
530-
#endif
531529
fields = 0xffff; /* everything */
532530
}
533531
break;
@@ -606,9 +604,7 @@ again: switch (c = *fmt++) {
606604
if (!isalnum((unsigned char)bp[abbr_len])) {
607605
tm->tm.tm_isdst = tz_info->is_dst;
608606
flb_tm_gmtoff(tm) = tz_info->offset_sec;
609-
#ifdef FLB_HAVE_TIME_ZONE
610-
tm->tm_zone = tz_info->abbr;
611-
#endif
607+
flb_tm_zone(tm) = tz_info->abbr;
612608
bp += abbr_len;
613609
found_in_known = 1;
614610
break;
@@ -627,16 +623,12 @@ again: switch (c = *fmt++) {
627623
if (strncmp((const char *)bp, gmt, 3) == 0) {
628624
tm->tm.tm_isdst = 0;
629625
flb_tm_gmtoff(tm) = 0;
630-
#ifdef FLB_HAVE_TIME_ZONE
631-
tm->tm_zone = gmt;
632-
#endif
626+
flb_tm_zone(tm) = gmt;
633627
bp += 3;
634628
} else if (strncmp((const char *)bp, utc, 3) == 0) {
635629
tm->tm.tm_isdst = 0;
636630
flb_tm_gmtoff(tm) = 0;
637-
#ifdef FLB_HAVE_TIME_ZONE
638-
tm->tm_zone = utc;
639-
#endif
631+
flb_tm_zone(tm) = utc;
640632
bp += 3;
641633
} else {
642634
ep = _find_string(bp, &i, (const char * const *)tzname, NULL, 2);
@@ -661,9 +653,7 @@ again: switch (c = *fmt++) {
661653
#else
662654
flb_tm_gmtoff(tm) = -(timezone);
663655
#endif
664-
#ifdef FLB_HAVE_TIME_ZONE
665-
tm->tm_zone = tzname[i];
666-
#endif
656+
flb_tm_zone(tm) = tzname[i];
667657
bp = ep;
668658
}
669659
}
@@ -697,9 +687,7 @@ again: switch (c = *fmt++) {
697687
return NULL;
698688
tm->tm.tm_isdst = 0;
699689
flb_tm_gmtoff(tm) = 0;
700-
#ifdef FLB_HAVE_TIME_ZONE
701-
tm->tm_zone = "GMT"; /* Original had global gmt array */
702-
#endif
690+
flb_tm_zone(tm) = "GMT"; /* Original had global gmt array */
703691
continue;
704692
case 'U':
705693
if (*bp++ != 'T')
@@ -709,16 +697,12 @@ again: switch (c = *fmt++) {
709697
bp++; /* Allow "UTC" */
710698
tm->tm.tm_isdst = 0;
711699
flb_tm_gmtoff(tm) = 0;
712-
#ifdef FLB_HAVE_TIME_ZONE
713-
tm->tm_zone = "UTC"; /* Original had global utc array */
714-
#endif
700+
flb_tm_zone(tm) = "UTC"; /* Original had global utc array */
715701
continue;
716702
case 'Z':
717703
tm->tm.tm_isdst = 0;
718704
flb_tm_gmtoff(tm) = 0;
719-
#ifdef FLB_HAVE_TIME_ZONE
720-
tm->tm_zone = utc;
721-
#endif
705+
flb_tm_zone(tm) = utc;
722706
continue;
723707
case '+':
724708
neg = 0;
@@ -732,19 +716,15 @@ again: switch (c = *fmt++) {
732716
if (ep != NULL) {
733717
flb_tm_gmtoff(tm) = (-5 - i) * SECSPERHOUR;
734718
tm->tm.tm_isdst = 0;
735-
#ifdef FLB_HAVE_TIME_ZONE
736-
tm->tm_zone = (char *)nast[i];
737-
#endif
719+
flb_tm_zone(tm) = (char *)nast[i];
738720
bp = ep;
739721
continue;
740722
}
741723
ep = _find_string(bp, &i, nadt, NULL, 4);
742724
if (ep != NULL) {
743725
tm->tm.tm_isdst = 1;
744726
flb_tm_gmtoff(tm) = (-4 - i) * SECSPERHOUR;
745-
#ifdef FLB_HAVE_TIME_ZONE
746-
tm->tm_zone = (char *)nadt[i];
747-
#endif
727+
flb_tm_zone(tm) = (char *)nadt[i];
748728
bp = ep;
749729
continue;
750730
}
@@ -766,9 +746,7 @@ again: switch (c = *fmt++) {
766746
offs = -offs;
767747
tm->tm.tm_isdst = 0; /* XXX */
768748
flb_tm_gmtoff(tm) = offs;
769-
#ifdef FLB_HAVE_TIME_ZONE
770-
tm->tm_zone = NULL; /* XXX */
771-
#endif
749+
flb_tm_zone(tm) = NULL; /* XXX */
772750
continue;
773751

774752
/*

0 commit comments

Comments
 (0)