[edk2-devel] Flush on main exit?

Tim Lewis tim.lewis at insyde.com
Fri Oct 18 21:13:24 UTC 2019


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
<https://pubs.opengroup.org/onlinepubs/009695399/functions/tmpfile.html>
tmpfile(). Finally, control shall be terminated with the consequences
described below.

 

I have seen similar behavior with CURL and printf. 

 

Any thoughts here?

 

Tim

 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#49247): https://edk2.groups.io/g/devel/message/49247
Mute This Topic: https://groups.io/mt/35145254/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20191018/f22c3f96/attachment.htm>


More information about the edk2-devel-archive mailing list