diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-11-01 12:33:22 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-11-05 09:22:02 -0500 |
commit | 6e7ff8cba0efaf803e3ef5b5aba4123633fe0658 (patch) | |
tree | 34d13bcfb483674e0ae52bd3fb60f371c20f0155 /src/lib/version/version.c | |
parent | 7bb76b24cf755799b7950ef078ac5ccf4d6e3a8a (diff) | |
download | tor-6e7ff8cba0efaf803e3ef5b5aba4123633fe0658.tar.gz tor-6e7ff8cba0efaf803e3ef5b5aba4123633fe0658.zip |
Move the code that knows our tor version into a lowest-level lib
Diffstat (limited to 'src/lib/version/version.c')
-rw-r--r-- | src/lib/version/version.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/version/version.c b/src/lib/version/version.c new file mode 100644 index 0000000000..29ada39c9d --- /dev/null +++ b/src/lib/version/version.c @@ -0,0 +1,50 @@ +/* Copyright 2001-2004 Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "orconfig.h" +#include "lib/version/torversion.h" +#include "lib/version/git_revision.h" + +#include <stdio.h> +#include <string.h> + +/** A shorter version of this Tor process's version, for export in our router + * descriptor. (Does not include the git version, if any.) */ +static const char the_short_tor_version[] = + VERSION +#ifdef TOR_BUILD_TAG + " ("TOR_BUILD_TAG")" +#endif + ""; + +#define MAX_VERSION_LEN 128 + +/** The version of this Tor process, possibly including git version */ +static char the_tor_version[MAX_VERSION_LEN] = ""; + +/** Return the current Tor version. */ +const char * +get_version(void) +{ + if (the_tor_version[0] == 0) { + if (strlen(tor_git_revision)) { + snprintf(the_tor_version, sizeof(the_tor_version), + "%s (git-%s)", the_short_tor_version, tor_git_revision); + } else { + snprintf(the_tor_version, sizeof(the_tor_version), + "%s", the_short_tor_version); + } + the_tor_version[sizeof(the_tor_version)-1] = 0; + } + + return the_tor_version; +} + +/** Return the current Tor version, without any git tag. */ +const char * +get_short_version(void) +{ + return the_short_tor_version; +} |