From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out03.hibox.biz (out03.hibox.biz [210.71.195.45]) by mx.groups.io with SMTP id smtpd.web11.1886.1571433210007209646 for ; Fri, 18 Oct 2019 14:13:30 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: insyde.com, ip: 210.71.195.45, mailfrom: tim.lewis@insyde.com) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2A8BQAPKKpd/w00GKxlHAEBAQEBBwE?= =?us-ascii?q?BEQEEBAEBgXuBHIEsRHQSKo0oiC8BhxKDbINDEYQWiAoJAQEBAQEBAQEBCCM?= =?us-ascii?q?JAQIBAYN7PwSDNTgTAgwBAQUBAQEBAQUEbYRrQgyFWgIjKTAFBhBSPwEEHgW?= =?us-ascii?q?DE4F5fg+yRBoChB0BgRSEdAaBNoFljEGBEYYyA4IthR8EljFElmAHgimHC44?= =?us-ascii?q?XG44mA4shlleRQ4FpIoFYcIM8EywREIFwF4hkhV8kMAGBIAgVAZBmAQE?= X-IronPort-AV: E=Sophos;i="5.67,313,1566835200"; d="scan'208,217";a="24932819" Received: from unknown (HELO hb3-BKT203.hibox.biz) ([172.24.52.13]) by out03.hibox.biz with ESMTP; 19 Oct 2019 05:13:28 +0800 Received: from unknown (HELO hb3-BKT101.hibox.biz) ([172.24.51.11]) by hb3-BKT203.hibox.biz with ESMTP; 19 Oct 2019 05:13:27 +0800 Received: from unknown (HELO hb3-IN03.hibox.biz) ([172.24.12.13]) by hb3-BKT101.hibox.biz with ESMTP; 19 Oct 2019 05:13:27 +0800 X-Remote-IP: 73.116.1.175 X-Remote-Host: c-73-116-1-175.hsd1.ca.comcast.net X-SBRS: -10.0 X-MID: 30651268 X-Auth-ID: tim.lewis@insyde.com X-EnvelopeFrom: tim.lewis@insyde.com hiBox-Sender: 1 Received: from c-73-116-1-175.hsd1.ca.comcast.net (HELO DESKTOPHG9V3E8) ([73.116.1.175]) by hb3-IN03.hibox.biz with ESMTP/TLS/AES256-SHA; 19 Oct 2019 05:13:26 +0800 From: "Tim Lewis" To: Subject: Flush on main exit? Date: Fri, 18 Oct 2019 14:13:24 -0700 Message-ID: <07be01d585f8$e27c05a0$a77410e0$@insyde.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdWF95NxWcfYLrJERhGabFuuIdDdqw== Content-Type: multipart/alternative; boundary="----=_NextPart_000_07BF_01D585BE.361E1800" Content-Language: en-us ------=_NextPart_000_07BF_01D585BE.361E1800 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I have noticed recently, when porting BSD applications, that if main exits normally, the buffers are not flushed. This is most obvious when using StdLib along with printf or fprintf to stdout. Has anyone else noticed this? If there is a \n in the output, it gets flushed to stdout, but if the string does not contain a \n then often nothing happens. This is most obvious with 1-line help or logo strings that never show up. Of course, most BSD apps use stderr for their usage, but even this doesn't go anywhere static void usage(void) { (void)fprintf(stderr, "usage: which [-as] program ...\n"); exit(EXIT_FAILURE); } Per the posix standard: OpenGroup says: https://pubs.opengroup.org/onlinepubs/009695399/functions/exit.html The exit() function shall then flush all open streams with unwritten buffered data, close all open streams, and remove all files created by tmpfile(). Finally, control shall be terminated with the consequences described below. I have seen similar behavior with CURL and printf. Any thoughts here? Tim ------=_NextPart_000_07BF_01D585BE.361E1800 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I have noticed recently, when porting BSD = applications, that if main exits normally, the buffers are not flushed. = This is most obvious when using StdLib along with printf or fprintf to = stdout.

 

Has anyone else noticed this? If there is a \n in the = output, it gets flushed to stdout, but if the string does not contain a = \n then often nothing happens. This is most obvious with 1-line help or = logo strings that never show up. Of course, most BSD apps use stderr for = their usage, but even this doesn’t go anywhere

 

static = void

usage(void)

{

 

         &= nbsp;     (void)fprintf(stderr, "usage: which = [-as] program ...\n");

         &= nbsp;     exit(EXIT_FAILURE);

}

 

Per the = posix standard:

 

OpenGroup = says:

https://pubs.opengroup.org/onlinepubs/009695399/functions/exit.html

 

The exit() function shall then flush all = open streams with unwritten buffered data, close all open streams, and = remove all files created by tmpfile(). Finally, control shall be terminated with the = consequences described below.

 

I have seen = similar behavior with CURL and printf.

 

Any thoughts = here?

 

Tim

 

------=_NextPart_000_07BF_01D585BE.361E1800--