<div dir="ltr"><div><a href="https://www.gnu.org/ghm/2011/paris/slides/jim-meyering-goodbye-world.pdf">https://www.gnu.org/ghm/2011/paris/slides/jim-meyering-goodbye-world.pdf</a></div><div><br></div><div>This article, which is written by Jim Meyering, teaches us how to write a robust "Hello World!” program. In this article I find out the reason why every linux command have this line of code "atexit (close_stdout);”. Let’s look at the beginning of main() function:</div><div><br></div><div>NetBSD</div><div> setprogname(argv[0]);</div><div> (void)setlocale(LC_ALL, "”); //Set current locale</div><div><br></div><div>Linux</div><div> initialize_main (&argc, &argv); //Something about VMS, fill * with real arguments</div><div> set_program_name (argv[0]);</div><div> setlocale (LC_ALL, "");</div><div> bindtextdomain (PACKAGE, LOCALEDIR); //Set directory containing message catalogs</div><div> textdomain (PACKAGE);</div><div> atexit (close_stdout); //Handle stdout error.</div><div><br></div><div>The “close_stdout" function will catch stdout error for example:</div><div><br></div><div>ls > /dev/full</div><div>ls: write error: No space left on device</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 16, 2014 at 10:15 PM, <a href="mailto:xxu15@stevens.edu">xxu15@stevens.edu</a> <span dir="ltr"><<a href="mailto:xxu15@stevens.edu" target="_blank">xxu15@stevens.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="MARGIN:10px">
<div>Hi,</div>
<div style="TEXT-INDENT:2em">I found that in many GNU Linux c files, at the
begining of the main() function, there are such functions being invoked as
below:</div>
<div style="TEXT-INDENT:2em"> </div>
<div style="TEXT-INDENT:4em">initialize_main (&argc, &argv); </div>
<div style="TEXT-INDENT:4em">set_program_name (argv[0]); </div>
<div style="TEXT-INDENT:4em">setlocale (LC_ALL, ""); </div>
<div style="TEXT-INDENT:4em">
<div style="TEXT-INDENT:4em">bindtextdomain (PACKAGE, LOCALEDIR); </div>
<div style="TEXT-INDENT:4em">textdomain (PACKAGE); </div>
<div style="TEXT-INDENT:4em"> </div></div>
<div style="TEXT-INDENT:2em">Has any body figured out what they are used
for ?</div>
<div> </div>
<hr style="WIDTH:210px;min-height:1px" align="left" color="#b5c4df" size="1">
<div><span>
<div style="FONT-FAMILY:verdana;FONT-SIZE:10pt">
<div>
<div>
<div>
<div>Sincerely,</div>
<div>Xiang Xu (徐祥) </div>
<div>Student ID: 10388813</div>
<div>tel: <a href="tel:%2B1%20%28201%29%20918-0570" value="+12019180570" target="_blank">+1 (201) 918-0570</a></div>
<div> <a href="tel:%2B86%2013851478402" value="+8613851478402" target="_blank">+86 13851478402</a></div>
<div>qq: 185904095</div></div></div></div></div></span></div></div>
<br>_______________________________________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/mailman/listinfo/cs631apue</a><br>
<br></blockquote></div><br></div>