• coreutils8.32 true命令和源码分析


    命令返回正常退出代码

    1. /* Exit with a status code indicating success.
    2. Copyright (C) 1999-2020 Free Software Foundation, Inc.
    3. This program is free software: you can redistribute it and/or modify
    4. it under the terms of the GNU General Public License as published by
    5. the Free Software Foundation, either version 3 of the License, or
    6. (at your option) any later version.
    7. This program is distributed in the hope that it will be useful,
    8. but WITHOUT ANY WARRANTY; without even the implied warranty of
    9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    10. GNU General Public License for more details.
    11. You should have received a copy of the GNU General Public License
    12. along with this program. If not, see . */
    13. #include
    14. #include
    15. #include
    16. #include "system.h"
    17. /* Act like "true" by default; false.c overrides this. */
    18. #ifndef EXIT_STATUS
    19. # define EXIT_STATUS EXIT_SUCCESS
    20. #endif
    21. #if EXIT_STATUS == EXIT_SUCCESS
    22. # define PROGRAM_NAME "true"
    23. #else
    24. # define PROGRAM_NAME "false"
    25. #endif
    26. #define AUTHORS proper_name ("Jim Meyering")
    27. /* 用法函数 */
    28. void
    29. usage (int status)
    30. {
    31. printf (_("\
    32. Usage: %s [ignored command line arguments]\n\
    33. or: %s OPTION\n\
    34. "),
    35. program_name, program_name);
    36. printf ("%s\n\n",
    37. _(EXIT_STATUS == EXIT_SUCCESS
    38. ? N_("Exit with a status code indicating success.")
    39. : N_("Exit with a status code indicating failure.")));
    40. fputs (HELP_OPTION_DESCRIPTION, stdout);
    41. fputs (VERSION_OPTION_DESCRIPTION, stdout);
    42. printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
    43. emit_ancillary_info (PROGRAM_NAME);
    44. exit (status);
    45. }
    46. int
    47. main (int argc, char **argv)
    48. {
    49. /* Recognize --help or --version only if it's the only command-line
    50. argument. */
    51. /* 命令有传入选项时,才进入该if */
    52. if (argc == 2)
    53. {
    54. /* 初始化 */
    55. initialize_main (&argc, &argv);
    56. set_program_name (argv[0]);
    57. setlocale (LC_ALL, "");
    58. bindtextdomain (PACKAGE, LOCALEDIR);
    59. textdomain (PACKAGE);
    60. /* Note true(1) will return EXIT_FAILURE in the
    61. edge case where writes fail with GNU specific options. */
    62. atexit (close_stdout);
    63. /* 用法函数 */
    64. if (STREQ (argv[1], "--help"))
    65. usage (EXIT_STATUS);
    66. /* 版本信息等 */
    67. if (STREQ (argv[1], "--version"))
    68. version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
    69. (char *) NULL);
    70. }
    71. /* 没有传入选项时,直接返回EXIT_STATUS正常退出代码 */
    72. return EXIT_STATUS;
    73. }

  • 相关阅读:
    【MySQL】超详细_数据库的约束_MySQL的详细查询
    手把手教你深度学习和实战-----循环神经网络
    java线上投保的设计计算机毕业设计源码
    代码随想录算法训练营第四十六天|139. 单词拆分、多重背包问题、总结
    如何配置多个ssh
    算法效率的计算
    Java.lang.Class类 isSynthetic()方法有什么功能呢?
    c++ 学习之 数据类型的取值范围
    FullCalendar日历插件说明文档
    当个 PM 式程序员「GitHub 热点速览」
  • 原文地址:https://blog.csdn.net/qq2260079443/article/details/126917016