Use FILE * instead of fd for files to support buffering