Factor out common C++ support functions into support.cc
Use istream::gcount() to find out how many byte we read
Implement index_ranges for C++