LCOV - code coverage report
Current view: top level - lib/version - version.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 9 88.9 %
Date: 2021-11-24 03:28:48 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* Copyright 2001-2004 Roger Dingledine.
       2             :  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
       3             :  * Copyright (c) 2007-2021, The Tor Project, Inc. */
       4             : /* See LICENSE for licensing information */
       5             : 
       6             : #include "orconfig.h"
       7             : #include "lib/version/torversion.h"
       8             : #include "lib/version/git_revision.h"
       9             : 
      10             : #include <stdio.h>
      11             : #include <string.h>
      12             : 
      13             : /**
      14             :  * @file version.c
      15             :  * @brief Functions to get the version of Tor.
      16             :  **/
      17             : 
      18             : /** A shorter version of this Tor process's version, for export in our router
      19             :  *  descriptor.  (Does not include the git version, if any.) */
      20             : static const char the_short_tor_version[] =
      21             :   VERSION
      22             : #ifdef TOR_BUILD_TAG
      23             :   " ("TOR_BUILD_TAG")"
      24             : #endif
      25             :   "";
      26             : 
      27             : /**
      28             :  * Longest possible version length. We make this a constant so that we
      29             :  * can statically allocate the_tor_version.
      30             :  **/
      31             : #define MAX_VERSION_LEN 128
      32             : 
      33             : /** The version of this Tor process, possibly including git version */
      34             : static char the_tor_version[MAX_VERSION_LEN] = "";
      35             : 
      36             : /** Return the current Tor version. */
      37             : const char *
      38        6215 : get_version(void)
      39             : {
      40        6215 :   if (the_tor_version[0] == 0) {
      41        5553 :     if (strlen(tor_git_revision)) {
      42        5553 :       snprintf(the_tor_version, sizeof(the_tor_version),
      43             :                "%s (git-%s)", the_short_tor_version, tor_git_revision);
      44             :     } else {
      45           0 :       snprintf(the_tor_version, sizeof(the_tor_version),
      46             :                "%s", the_short_tor_version);
      47             :     }
      48        5553 :     the_tor_version[sizeof(the_tor_version)-1] = 0;
      49             :   }
      50             : 
      51        6215 :   return the_tor_version;
      52             : }
      53             : 
      54             : /** Return the current Tor version, without any git tag. */
      55             : const char *
      56           7 : get_short_version(void)
      57             : {
      58           7 :   return the_short_tor_version;
      59             : }

Generated by: LCOV version 1.14