[cs631apue] starting functions in GNU Linux mian()

Jin Sun jsun6 at stevens.edu
Wed Sep 17 01:35:32 EDT 2014


https://www.gnu.org/ghm/2011/paris/slides/jim-meyering-goodbye-world.pdf

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:

NetBSD
  setprogname(argv[0]);
  (void)setlocale(LC_ALL, "”);      //Set current locale

Linux
  initialize_main (&argc, &argv);      //Something about VMS, fill * with
real arguments
  set_program_name (argv[0]);
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);  //Set directory containing message
catalogs
  textdomain (PACKAGE);
  atexit (close_stdout);        //Handle stdout error.

The “close_stdout" function will catch stdout error for example:

ls > /dev/full
ls: write error: No space left on device

On Tue, Sep 16, 2014 at 10:15 PM, xxu15 at stevens.edu <xxu15 at stevens.edu>
wrote:

>  Hi,
> I found that in many GNU Linux c files, at the begining of the main()
> function, there are such functions being invoked as below:
>
> initialize_main (&argc, &argv);
> set_program_name (argv[0]);
> setlocale (LC_ALL, "");
>  bindtextdomain (PACKAGE, LOCALEDIR);
> textdomain (PACKAGE);
>
> Has any body figured out what they are used for ?
>
> ------------------------------
>    Sincerely,
> Xiang Xu (徐祥)
> Student ID: 10388813
> tel: +1 (201) 918-0570
>       +86 13851478402
> qq: 185904095
>
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20140917/bdb17da9/attachment-0001.html>


More information about the cs631apue mailing list