version.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright 2001-2004 Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "orconfig.h"
  6. #include "lib/version/torversion.h"
  7. #include "lib/version/git_revision.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10. /** A shorter version of this Tor process's version, for export in our router
  11. * descriptor. (Does not include the git version, if any.) */
  12. static const char the_short_tor_version[] =
  13. VERSION
  14. #ifdef TOR_BUILD_TAG
  15. " ("TOR_BUILD_TAG")"
  16. #endif
  17. "";
  18. #define MAX_VERSION_LEN 128
  19. /** The version of this Tor process, possibly including git version */
  20. static char the_tor_version[MAX_VERSION_LEN] = "";
  21. /** Return the current Tor version. */
  22. const char *
  23. get_version(void)
  24. {
  25. if (the_tor_version[0] == 0) {
  26. if (strlen(tor_git_revision)) {
  27. snprintf(the_tor_version, sizeof(the_tor_version),
  28. "%s (git-%s)", the_short_tor_version, tor_git_revision);
  29. } else {
  30. snprintf(the_tor_version, sizeof(the_tor_version),
  31. "%s", the_short_tor_version);
  32. }
  33. the_tor_version[sizeof(the_tor_version)-1] = 0;
  34. }
  35. return the_tor_version;
  36. }
  37. /** Return the current Tor version, without any git tag. */
  38. const char *
  39. get_short_version(void)
  40. {
  41. return the_short_tor_version;
  42. }