Tor  0.4.6.0-alpha-dev
libc.c
Go to the documentation of this file.
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-2020, 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 *
33 {
34 #ifdef __GLIBC__
35  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 *
45 {
46 #ifdef CHECK_LIBC_VERSION
47  const char *version = gnu_get_libc_version();
48  if (version == NULL)
49  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 *
60 {
61 #ifdef __GLIBC__
62  return STR(__GLIBC__) "." STR(__GLIBC_MINOR__);
63 #else
64  return "N/A";
65 #endif /* defined(__GLIBC__) */
66 }
libc.h
Header for lib/osinfo/libc.c.
tor_libc_get_header_version_str
const char * tor_libc_get_header_version_str(void)
Definition: libc.c:59
tor_libc_get_version_str
const char * tor_libc_get_version_str(void)
Definition: libc.c:44
tor_libc_get_name
const char * tor_libc_get_name(void)
Definition: libc.c:32