LCOV - code coverage report
Current view: top level - lib/osinfo - libc.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 5 8 62.5 %
Date: 2021-11-24 03:28:48 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* Copyright (c) 2001 Matej Pfajfar.
       2             :  * Copyright (c) 2001-2004, Roger Dingledine.
       3             :  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
       4             :  * Copyright (c) 2007-2021, The Tor Project, Inc. */
       5             : /* See LICENSE for licensing information */
       6             : 
       7             : /**
       8             :  * @file libc.c
       9             :  * @brief Functions to get the name and version of the system libc.
      10             :  **/
      11             : 
      12             : #include "orconfig.h"
      13             : #include "lib/osinfo/libc.h"
      14             : #include <stdlib.h>
      15             : 
      16             : #ifdef HAVE_GNU_LIBC_VERSION_H
      17             : #include <gnu/libc-version.h>
      18             : #endif
      19             : 
      20             : #ifdef HAVE_GNU_LIBC_VERSION_H
      21             : #ifdef HAVE_GNU_GET_LIBC_VERSION
      22             : #define CHECK_LIBC_VERSION
      23             : #endif
      24             : #endif
      25             : 
      26             : #define STR_IMPL(x) #x
      27             : #define STR(x) STR_IMPL(x)
      28             : 
      29             : /** Return the name of the compile time libc. Returns NULL if we
      30             :  * cannot identify the libc. */
      31             : const char *
      32         470 : tor_libc_get_name(void)
      33             : {
      34             : #ifdef __GLIBC__
      35         470 :   return "Glibc";
      36             : #else /* !defined(__GLIBC__) */
      37             :   return NULL;
      38             : #endif /* defined(__GLIBC__) */
      39             : }
      40             : 
      41             : /** Return a string representation of the version of the currently running
      42             :  * version of Glibc. */
      43             : const char *
      44         235 : tor_libc_get_version_str(void)
      45             : {
      46             : #ifdef CHECK_LIBC_VERSION
      47         235 :   const char *version = gnu_get_libc_version();
      48         235 :   if (version == NULL)
      49           0 :     return "N/A";
      50             :   return version;
      51             : #else /* !defined(CHECK_LIBC_VERSION) */
      52             :   return "N/A";
      53             : #endif /* defined(CHECK_LIBC_VERSION) */
      54             : }
      55             : 
      56             : /** Return a string representation of the version of Glibc that was used at
      57             :  * compilation time. */
      58             : const char *
      59           0 : tor_libc_get_header_version_str(void)
      60             : {
      61             : #ifdef __GLIBC__
      62           0 :   return STR(__GLIBC__) "." STR(__GLIBC_MINOR__);
      63             : #else
      64             :   return "N/A";
      65             : #endif /* defined(__GLIBC__) */
      66             : }

Generated by: LCOV version 1.14