| 1124 | */ |
| 1125 | |
| 1126 | static const char * |
| 1127 | tformat(void) |
| 1128 | { |
| 1129 | #if HAVE__GENERIC |
| 1130 | /* C11-style _Generic is more likely to return the correct |
| 1131 | format when distinct types have the same size. */ |
| 1132 | char const *fmt = |
| 1133 | _Generic(+ (time_t) 0, |
| 1134 | int: "%d", long: "%ld", long long: "%lld", |
| 1135 | unsigned: "%u", unsigned long: "%lu", |
| 1136 | unsigned long long: "%llu", |
| 1137 | default: NULL); |
| 1138 | if (fmt) |
| 1139 | return fmt; |
| 1140 | fmt = _Generic((time_t) 0, |
| 1141 | intmax_t: "%"PRIdMAX, uintmax_t: "%"PRIuMAX, |
| 1142 | default: NULL); |
| 1143 | if (fmt) |
| 1144 | return fmt; |
| 1145 | #endif |
| 1146 | if (0 > (time_t) -1) { /* signed */ |
| 1147 | if (sizeof(time_t) == sizeof(intmax_t)) |
| 1148 | return "%"PRIdMAX; |
| 1149 | if (sizeof(time_t) > sizeof(long)) |
| 1150 | return "%lld"; |
| 1151 | if (sizeof(time_t) > sizeof(int)) |
| 1152 | return "%ld"; |
| 1153 | return "%d"; |
| 1154 | } |
| 1155 | #ifdef PRIuMAX |
| 1156 | if (sizeof(time_t) == sizeof(uintmax_t)) |
| 1157 | return "%"PRIuMAX; |
| 1158 | #endif |
| 1159 | if (sizeof(time_t) > sizeof(unsigned long)) |
| 1160 | return "%llu"; |
| 1161 | if (sizeof(time_t) > sizeof(unsigned int)) |
| 1162 | return "%lu"; |
| 1163 | return "%u"; |
| 1164 | } |
| 1165 | |
| 1166 | static void |
| 1167 | dumptime(register const struct tm *timeptr) |