MCPcopy Create free account
hub / github.com/git/git / getchar_with_timeout

Function getchar_with_timeout

compat/terminal.c:220–245  ·  view source on GitHub ↗

* On macos it is not possible to use poll() with a terminal so use select * instead. */

Source from the content-addressed store, hash-verified

218 * instead.
219 */
220static 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

Callers 1

read_key_without_echoFunction · 0.85

Calls 1

pollFunction · 0.85

Tested by

no test coverage detected