• 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. }

  • 相关阅读:
    多版本并发控制 mvcc
    [网鼎杯 2020 青龙组]AreUSerialz
    【C++】循环(for/while/do-while)和关系表达式
    Java面试题-0919
    从输入URL到页面展示发生了什么?
    1.3.OpenCV技能树--第一单元--图像的基础操作(基础篇)
    船舶稳定性和静水力计算——绘图体平面图,静水力,GZ计算(Matlab代码实现)
    医疗知识图谱 neo4j
    【JVM】java的jvm类加载器和类加载子系统
    Redis 不行了?
  • 原文地址:https://blog.csdn.net/qq2260079443/article/details/126917016