Many updates and bugfixes (and some leftover stylistic diffs)

Please review this code and update your own as you see fit.  There are several key bugs that were fixed, and at least two utility functions were rewritten.  The return value from tf_fread and tf_fwrite were changed to the number of bytes read or written to stick closer to the posix api.
Sorry, but you'll notice my changes are using 4-space indentation.  It's easily changed back if you choose.