| 153 | that this function is first run. */ |
| 154 | |
| 155 | static char const * |
| 156 | idle_string (time_t when) |
| 157 | { |
| 158 | static time_t now = 0; |
| 159 | static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "d"]; |
| 160 | |
| 161 | if (now == 0) |
| 162 | time (&now); |
| 163 | |
| 164 | time_t seconds_idle = now - when; |
| 165 | if (seconds_idle < 60) /* One minute. */ |
| 166 | return " "; |
| 167 | if (seconds_idle < (24 * 60 * 60)) /* One day. */ |
| 168 | { |
| 169 | int hours = seconds_idle / (60 * 60); |
| 170 | int minutes = (seconds_idle % (60 * 60)) / 60; |
| 171 | sprintf (buf, "%02d:%02d", hours, minutes); |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | intmax_t days = seconds_idle / (24 * 60 * 60); |
| 176 | sprintf (buf, "%jdd", days); |
| 177 | } |
| 178 | return buf; |
| 179 | } |
| 180 | |
| 181 | /* Return a time string. */ |
| 182 | static char const * |