* On macos it is not possible to use poll() with a terminal so use select * instead. */
| 218 | * instead. |
| 219 | */ |
| 220 | static int getchar_with_timeout(int timeout) |
| 221 | { |
| 222 | struct timeval tv, *tvp = NULL; |
| 223 | fd_set readfds; |
| 224 | int res; |
| 225 | |
| 226 | again: |
| 227 | if (timeout >= 0) { |
| 228 | tv.tv_sec = timeout / 1000; |
| 229 | tv.tv_usec = (timeout % 1000) * 1000; |
| 230 | tvp = &tv; |
| 231 | } |
| 232 | |
| 233 | FD_ZERO(&readfds); |
| 234 | FD_SET(0, &readfds); |
| 235 | res = select(1, &readfds, NULL, NULL, tvp); |
| 236 | if (!res) |
| 237 | return EOF; |
| 238 | if (res < 0) { |
| 239 | if (errno == EINTR) |
| 240 | goto again; |
| 241 | else |
| 242 | return EOF; |
| 243 | } |
| 244 | return getchar(); |
| 245 | } |
| 246 | |
| 247 | #elif defined(GIT_WINDOWS_NATIVE) |
| 248 |
no test coverage detected