Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csq.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
#include <errno.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
#include "bcftools.h"
#include "filter.h"
#include "regidx.h"
Expand Down
1 change: 1 addition & 0 deletions gff.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include <strings.h>
#include <htslib/hts.h>
#include <htslib/khash.h>
#include <htslib/khash_str2int.h>
Expand Down
13 changes: 12 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ THE SOFTWARE. */
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <htslib/hts.h>
#include "version.h"
#include "bcftools.h"
Expand Down Expand Up @@ -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++;
}
Expand Down
1 change: 1 addition & 0 deletions plugins/tag2tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. */

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <getopt.h>
#include <math.h>
#include <inttypes.h>
Expand Down