Make the error message about unexpected '#ifdef HAVE_XXX' clearer. Protect sys/stat.h #includes with the corresponding '#ifdef HAVE_XXX' check.
thread, when a bad stream is encountered.