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.
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 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
Compiling using CLANG gives the following errors:
Undefined symbols for architecture x86_64:
"_bwt_occ", referenced from:
_bwt_cal_sa in bwt.o
_bwt_sa in bwt.o
"_bwt_2occ", referenced from:
_bwt_match_exact in bwt.o
_bwt_match_exact_alt in bwt.o
_bwt_cal_width in bwtaln.o
"_bwt_2occ4", referenced from:
_bwt_match_gap in bwtgap.o
_bsw2_core in bwtsw2_core.o
"_bwtl_2occ4", referenced from:
_bsw2_core in bwtsw2_core.o