diff --git a/csq.c b/csq.c index f619e061a..5a11179a3 100644 --- a/csq.c +++ b/csq.c @@ -149,6 +149,7 @@ #include #include #include +#include #include "bcftools.h" #include "filter.h" #include "regidx.h" diff --git a/gff.c b/gff.c index 5d9f062be..6ec5a5875 100644 --- a/gff.c +++ b/gff.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/main.c b/main.c index a0213589f..f5618c56b 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,7 @@ THE SOFTWARE. */ #include #include #include +#include #include #include "version.h" #include "bcftools.h" @@ -300,7 +301,17 @@ int main(int argc, char *argv[]) { if (cmds[i].func && strcmp(argv[1],cmds[i].alias)==0) { - return cmds[i].func(argc-1,argv+1); + int ret = cmds[i].func(argc-1,argv+1); + + // For subcommands that may have produced substantial output on stdout, + // make a final check for delayed I/O errors. Ignore EBADF as other code + // may have already closed stdout. + if (fclose(stdout) != 0 && errno != EBADF) { + fprintf(stderr, "[E::%s] closing standard output failed\n", __func__); + return 1; + } + + return ret; } i++; } diff --git a/plugins/tag2tag.c b/plugins/tag2tag.c index 92ee2e478..387b9eec8 100644 --- a/plugins/tag2tag.c +++ b/plugins/tag2tag.c @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */ #include #include +#include #include #include #include