Adding fdopen, fixing fread behavior