Link Search Menu Expand Document

サマリ:base64のソースコードリーディング2回目

base64を読もう②

mainを見ます。

  initialize_main (&argc, &argv);

initialize_mainsystem.hで次のように定義されています。

/* Redirection and wildcarding when done by the utility itself.
   Generally a noop, but used in particular for OS/2.  */
#ifndef initialize_main
# ifndef __OS2__
#  define initialize_main(ac, av)
# else
#  define initialize_main(ac, av) \
     do { _wildcard (ac, av); _response (ac, av); } while (0)
# endif
#endif

リダイレクトやワイルドカードの扱い方を変更しますが、OS/2の一部を除いては、通常は何もしないと書かれています。

  set_program_name (argv[0]);

system.hprogram.hをincludeしており、そこで次のように定義されています。

/* String containing name the program is called with.  */
extern const char *program_name;

/* Set program_name, based on argv[0].  */
extern void set_program_name (const char *argv0);

結局のところ、グローバル変数であるprogram_nameに実行ファイル名を代入するだけのようです。実装の詳細は [http://www.opensource.apple.com/source/libiconv/libiconv-26/libiconv/srclib/progname.c:title] にあります。

  atexit (close_stdout);

atexitstdlib.hで定義され、終了時に呼び出す関数を登録しておく。system.hcloseout.hをincludeしており、close_stdoutはそこで定義されています。close_stdoutは簡潔に言えば、stdoutstderrを閉じ、エラーが生じれば、エラーコードで終了するもの。実装の詳細は[http://www.opensource.apple.com/source/text_cmds/text_cmds-88/sort/closeout.c:title]にあります。

###理解できたこと

  • set_program_nameatexitなどの便利なものはきちんと利用すること

###宿題

  • close_stdoutの実装がイマイチ理解できていないので見直す

今日はここまで。良い天気になりますように。


Back to top

Copyright © 2021- Akira Otaka All rights reserved.