main.cpp 614 B

12345678910111213141516
  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. int main() {
  5. auto handle = (unsigned long long)_get_osfhandle(0);
  6. fprintf(stderr, "_get_osfhandle(0)=%llu\n", handle);
  7. // It look's like classic windows undocumented behaviour
  8. // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle
  9. // _get_osfhandle returns INVALID_HANDLE_VALUE - 1 without any sign of error if specified fd was closed.
  10. // Working with such handle will lead to future various errors.
  11. if (handle + 1 == (unsigned long long)INVALID_HANDLE_VALUE) {
  12. return 1;
  13. }
  14. return 0;
  15. }