| 2838 | } |
| 2839 | |
| 2840 | static time_t |
| 2841 | time1(struct tm *const tmp, |
| 2842 | struct tm *funcp(struct state const *, time_t const *, |
| 2843 | int_fast32_t, struct tm *), |
| 2844 | struct state const *sp, |
| 2845 | const int_fast32_t offset) |
| 2846 | { |
| 2847 | register time_t t; |
| 2848 | register int samei, otheri; |
| 2849 | register int sameind, otherind; |
| 2850 | register int i; |
| 2851 | register int nseen; |
| 2852 | char seen[TZ_MAX_TYPES]; |
| 2853 | unsigned char types[TZ_MAX_TYPES]; |
| 2854 | bool okay; |
| 2855 | |
| 2856 | if (tmp == NULL) { |
| 2857 | errno = EINVAL; |
| 2858 | return WRONG; |
| 2859 | } |
| 2860 | if (tmp->tm_isdst > 1) |
| 2861 | tmp->tm_isdst = 1; |
| 2862 | t = time2(tmp, funcp, sp, offset, &okay); |
| 2863 | if (okay) |
| 2864 | return t; |
| 2865 | if (tmp->tm_isdst < 0) |
| 2866 | #ifdef PCTS |
| 2867 | /* |
| 2868 | ** POSIX Conformance Test Suite code courtesy Grant Sullivan. |
| 2869 | */ |
| 2870 | tmp->tm_isdst = 0; /* reset to std and try again */ |
| 2871 | #else |
| 2872 | return t; |
| 2873 | #endif /* !defined PCTS */ |
| 2874 | /* |
| 2875 | ** We're supposed to assume that somebody took a time of one type |
| 2876 | ** and did some math on it that yielded a "struct tm" that's bad. |
| 2877 | ** We try to divine the type they started from and adjust to the |
| 2878 | ** type they need. |
| 2879 | */ |
| 2880 | if (sp == NULL) |
| 2881 | return WRONG; |
| 2882 | for (i = 0; i < sp->typecnt; ++i) |
| 2883 | seen[i] = false; |
| 2884 | nseen = 0; |
| 2885 | for (i = sp->timecnt - 1; i >= 0; --i) |
| 2886 | if (!seen[sp->types[i]] && !ttunspecified(sp, sp->types[i])) { |
| 2887 | seen[sp->types[i]] = true; |
| 2888 | types[nseen++] = sp->types[i]; |
| 2889 | } |
| 2890 | for (sameind = 0; sameind < nseen; ++sameind) { |
| 2891 | samei = types[sameind]; |
| 2892 | if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) |
| 2893 | continue; |
| 2894 | for (otherind = 0; otherind < nseen; ++otherind) { |
| 2895 | otheri = types[otherind]; |
| 2896 | if (sp->ttis[otheri].tt_isdst != tmp->tm_isdst) { |
| 2897 | int sec = tmp->tm_sec; |
no test coverage detected