Also add missing declarations to misc. functions. Fix clearerr() implementation (previous was broken). Handle feature test macros like _POSIX_C_SOURCE properly. Change-Id: Icdc973a6b9d550a166fc2545f727ea837fe800c4