#include #include #include #include int main() { if (sizeof(struct tm) <= 4) { std::cout << "sizeof(struct tm) == 4\n"; return EXIT_SUCCESS; } /* just in the range of 32-bit */ int64_t exp_result = 2147483647LL; struct tm tb = { 7, 14, 4, 19, 0, 138, 0, 0, -1 }; int64_t t = std::mktime(&tb); if (t != exp_result) { std::cout << "wrong result for 32-bit time (off by " << (exp_result - std::mktime(&tb)) << ")\n"; return EXIT_FAILURE; } /* not in range, anymore, needs proper 64-bit processing */ tb.tm_sec += 1; exp_result += 1; t = std::mktime(&tb); if (t == -1) { std::cout << "crippled mktime detected (got -1)\n"; return EXIT_FAILURE; } else if (t != exp_result) { std::cout << "wrong result for 64-bit time (off by " << (exp_result - std::mktime(&tb)) << ")\n"; return EXIT_FAILURE; } else { std::cout << "mktime seems okay" << std::endl; return EXIT_SUCCESS; } }