]> git.tuebingen.mpg.de Git - paraslash.git/blob - version.c
sched.h: Remove outdated comment.
[paraslash.git] / version.c
1 #include "para.h"
2
3 /** \file version.h Macros for printing the version string. */
4
5 #include "git-version.h"
6
7 /**
8  * Get the raw git version string
9  *
10  * \return The string generated by the GIT-VERSION-GEN script. It is passed
11  * as a preprocessor define during compilation.
12  */
13 __a_const const char *version_git(void)
14 {
15         return GIT_VERSION;
16 }
17
18 /**
19  * Get the version string for an executable.
20  *
21  * \param pfx The program name (without the leading "para_").
22  *
23  * \return A statically allocated string which contains the program name, the
24  * git version and the codename. It must not be freed by the caller.
25  */
26 const char *version_single_line(const char *pfx)
27 {
28         static char buf[100];
29         snprintf(buf, sizeof(buf) - 1,
30                 "para_%s " GIT_VERSION, pfx);
31         return buf;
32 }
33
34 /**
35  * Get the full version text.
36  *
37  * \param pfx See \ref version_single_line().
38  *
39  * \return A string containing the same text as returned by \ref
40  * version_single_line(), augmented by additional build information, a
41  * copyright text and the email address of the author.
42  *
43  * Like \ref version_single_line(), this string is stored in a statically
44  * allocated buffer and must not be freed.
45  */
46 const char *version_text(const char *pfx)
47 {
48         static char buf[512];
49
50         snprintf(buf, sizeof(buf) - 1, "%s\n"
51                 "Copyright (C) 2013 Andre Noll\n"
52                 "This is free software with ABSOLUTELY NO WARRANTY."
53                 " See COPYING for details.\n"
54                 "Report bugs to <maan@systemlinux.org>.\n"
55                 "build date: " BUILD_DATE ",\n"
56                 "build system: " UNAME_RS ",\n"
57                 "compiler: " CC_VERSION ".\n",
58                 version_single_line(pfx)
59         );
60         return buf;
61 }
62
63 /**
64  * Print the version text and exit successfully.
65  *
66  * \param pfx See \ref version_single_line().
67  * \param flag Whether --version was given.
68  *
69  * If \a flag is false, this function does nothing. Otherwise it prints the
70  * full version text as returned by \ref version_text() and exits successfully.
71  */
72 void version_handle_flag(const char *pfx, bool flag)
73 {
74         if (!flag)
75                 return;
76         printf("%s", version_text(pfx));
77         exit(EXIT_SUCCESS);
78 }