From: Nicolas Williams Date: Fri, 29 May 2015 16:50:08 +0000 (-0500) Subject: Better handling of stdout errors X-Git-Tag: jq-1.5rc2~80 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a79f1d0a36fcd8ce8ff0800282605d9bdee55c4;p=jq Better handling of stdout errors --- diff --git a/main.c b/main.c index 8f0718e..6b4d5b9 100644 --- a/main.c +++ b/main.c @@ -161,6 +161,7 @@ int main(int argc, char* argv[]) { int compiled = 0; int parser_flags = 0; int nfiles = 0; + int badwrite; jv program_arguments = jv_array(); if (argc) progname = argv[0]; @@ -487,8 +488,8 @@ int main(int argc, char* argv[]) { ret = 2; out: - /* XXX We really should catch ENOSPC and such errors in jv_dumpf()! */ - if (fclose(stdout)!=0) { + badwrite = ferror(stdout); + if (fclose(stdout)!=0 || badwrite) { fprintf(stderr,"Error: writing output failed: %s\n", strerror(errno)); ret = 2; }