MCPcopy Create free account
hub / github.com/Genivia/ugrep / file_ready

Method file_ready

lib/input.cpp:1029–1068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1027}
1028
1029bool Input::file_ready()
1030{
1031 if (file_ == NULL || feof(file_))
1032 return false;
1033#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(__BORLANDC__)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
1034 return !ferror(file_);
1035#else
1036 int fd = fileno(file_);
1037 if (ferror(file_))
1038 {
1039 if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
1040 return false;
1041#if defined(__linux__)
1042 // Linux has regular files that can be set non-blocking to raise EAGAIN e.g. /proc and /sys
1043 if (errno == EAGAIN)
1044 {
1045 struct stat buf;
1046 if (fstat(fd, &buf) == 0 && S_ISREG(buf.st_mode))
1047 return false;
1048 }
1049#endif
1050 }
1051 while (true)
1052 {
1053 struct timeval tv;
1054 fd_set rfds, efds;
1055 FD_ZERO(&rfds);
1056 FD_ZERO(&efds);
1057 FD_SET(fd, &rfds);
1058 FD_SET(fd, &efds);
1059 tv.tv_sec = 0;
1060 tv.tv_usec = 10000; // 10ms timeout
1061 clearerr(file_); // unset EAGAIN etc
1062 if (::select(fd + 1, &rfds, NULL, &efds, &tv) >= 0)
1063 return FD_ISSET(fd, &efds) == 0;
1064 if (errno != EINTR)
1065 return false;
1066 }
1067#endif
1068}
1069
1070void Input::wstring_size()
1071{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected