Added more wrappers for functions that make system calls

Added the following wrappers that check the results of system calls
and exit non-zero if something went wrong.  This is so bwa can be more
robust against system failures (e.g. IO errors from remote storage, or
running out of memory).  The existing and new wrappers have also been
modified so that they no longer try to dump core on failure.  In most cases
the resulting core files are not useful (especially if bwa was compiled
with optimization turned on) so just pollute whatever directories they
got written to.

Wrappers for memory allocation functions:

xcalloc
xmalloc
xrealloc
xstrdup

New wrappers for IO functions:

err_fread_noeof   (also dies on EOF)
err_gzread
err_fseek
err_rewind
err_ftell
Use wrapper functions to catch system errors

Use the wrapper functions in utils.c plus a few extra bits of error
checking code to catch system errors and exit non-zero when they occur.
New wrapper for gzclose; added err_fflush calls and made it call fsync too.

Added a new utils.c wrapper err_gzclose and changed gzclose calls to use it.

Put in some more err_fflush calls before files being written are closed.

Made err_fflush call fsync.  This is useful for remote filesystems where
errors may not be reported on fflush or fclose as problems at the server
end may only be detected after they have returned.  If bwa is being used
only to write to local filesystems, calling fsync is not really necessary.
To disable it, comment out #define FSYNC_ON_FLUSH in utils.c.
Added wrappers for fputc and fputs; more efficient sequence printing

Added wrappers err_fputc and err_fputs to catch failures in fput and fputs.
Macros err_putchar and err_puts call the new wrappers and can be used in
place of putchar and puts.

To avoid having to make millions of function calls when printing out
sequences, the code to print them in bwa_print_sam1 using putchar has
been replaced by a new version in bwa_print_seq that puts the sequence
into a buffer and then outputs the lot with err_fwrite.  In testing, the
new code was slightly faster than the old version, with the added benefit
that it will stop promptly if IO problems are detected.
Merge branch 'master' into master_fixes

Merged to master version b621d3a

Conflicts:
	Makefile
	bntseq.c
	bwa.c
	bwase.c
	bwaseqio.c
	bwtaln.c
	bwtindex.c
	bwtio.c
	bwtmisc.c
	bwtsw2_aux.c
	cs2nt.c
	fastmap.c
	khash.h
	kseq.h
	ksw.c
	kvec.h
	simple_dp.c
	utils.c
	utils.h
Merge branch 'master' into master_fixes

Merge changes to commit c5434ac (0.7.0 release)

Conflicts:
	Makefile
	bwamem.c
Merge branch 'master' into master_fixes

Conflicts:
	bntseq.c
	bwamem.c
Merge branch 'master' into master_fixes

Conflicts:
	Makefile
	bwape.c
	bwase.c
	bwtsw2_aux.c
	stdaln.c
Merge branch 'master' into master_fixes

Conflicts:
	Makefile
Added Makefile.bak and bwamem-lite to .gitignore
Merge branch 'master' into master_fixes

Conflicts:
	bwamem.c
	bwamem_pair.c
	example.c
Merge branch 'master' into master_fixes
Merge branch 'master' into master_fixes
Merge branch 'master' into master_fixes.  Merged up to master r375.

Conflicts:
	bwt.c
Merge branch 'master' into master_fixes
Merge branch 'master' into master_fixes
Merge branch 'master' into master_fixes.  Merged up to release bwa-0.7.4-r385.
Merge branch 'master' into master_fixes.  Merged up to r389.

Conflicts:
	bwamem.c
	kopen.c
Ensure exit status of 1 if given invalid options or index files are not found.

Added missing default cases in option scanning.
Ensure exit value is 1 if bwa_idx_load or bwa_idx_infer_prefix fail.
These changes extend the previous one, which only fixed the mem aligner.
Reduce dependency on utils.h - new malloc wrapping scheme.

Remove xmalloc, xcalloc, xrealloc and xstrdup from utils.h and revert calls
to the normal malloc, calloc, realloc, strdup.  Add new files malloc_wrap.[ch]
with the wrapper functions.  malloc_wrap.h #defines malloc etc. to the
wrapper, but only if USE_MALLOC_WRAPPERS has been defined.

Put #include "malloc_wrap.h" in any file that uses *alloc or strdup.  This
is also in a #ifdef USE_MALLOC_WRAPPERS ... #endif block to make using the
wrappers optional.  Add -DUSE_MALLOC_WRAPPERS into the makefile so they
should normally get added.

This is an improvement on the previous method as we now don't need to
worry about stray function calls that were not changed to the wrapped version
and the code will still work even if the wrapping is disabled.

Other possible methods of doing this are using malloc_hook (glibc-specific),
adding -include malloc_wrap.h to the gcc command-line (somewhat
gcc-specific) or making our own malloc function and using dlopen (scary).
This way is probably the most portable.