aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/ut/stdin_osfhandle/main.cpp
blob: fe2ea836a9624f75ad9fe00ff7a7963250ceb1be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <io.h>
#include <stdio.h>
#include <windows.h>

int main() {
    auto handle = (unsigned long long)_get_osfhandle(0);
    fprintf(stderr, "_get_osfhandle(0)=%llu\n", handle);
    // It look's like classic windows undocumented behaviour
    // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle
    // _get_osfhandle returns INVALID_HANDLE_VALUE - 1 without any sign of error if specified fd was closed.
    // Working with such handle will lead to future various errors.
    if (handle + 1 == (unsigned long long)INVALID_HANDLE_VALUE)
        return 1;
    return 0;
}