[WIP] move function defs from misc2.c to fileio.c

In effort to eliminate the need for misc2.c (#209), I have pulled out various functions defined in misc2.c related to file IO to, correspondingly, fileio.c.