samtools / bcftools

This is the official development repository for BCFtools. See installation instructions and other documentation here http://samtools.github.io/bcftools/howtos/install.html
http://samtools.github.io/bcftools/
Other
649 stars 240 forks source link

Check fclose(stdout) at the end of main() [and miscellanea] #2046

Open jmarshall opened 9 months ago

jmarshall commented 9 months ago

Similar to samtools/samtools#1909, this is a companion pull request to samtools/htslib#1665. Now that hts_open("-", "w") / hts_close() no longer actually closes stdout. Close it explicitly at the end of main() when a subcommand may have written to stdout, so there is an opportunity to detect I/O errors in previously-uncommitted writes.

Ignore EBADF as other code may have already closed stdout, e.g., either particular subcommands or when (dynamically) linked against an older version of HTSlib.

Also trivially: include <strings.h> where needed to ensure strcasecmp() et al are declared. (<strings.h> is often a byproduct of <string.h> but POSIX doesn't require that.)