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

Conversation

jmarshall
Copy link
Member

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.)

Since PR samtools/htslib#1665, hts_open("-", "w") / hts_close() no longer
actually closes stdout. Close it at the end of main() 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.
Other source files that use strcase*() functions #include <strings.h>
themselves, so do so for this source file too. (<strings.h> is often
a byproduct of <string.h> but POSIX doesn't require that.)
@jmarshall jmarshall marked this pull request as draft November 27, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant