Add changes file for bug40642.
[tor.git] / src / lib / osinfo / libc.c
blobf52dea41aacca910dfbe45696c50c194779f63b6
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 */
7 /**
8 * @file libc.c
9 * @brief Functions to get the name and version of the system libc.
10 **/
12 #include "orconfig.h"
13 #include "lib/osinfo/libc.h"
14 #include <stdlib.h>
16 #ifdef HAVE_GNU_LIBC_VERSION_H
17 #include <gnu/libc-version.h>
18 #endif
20 #ifdef HAVE_GNU_LIBC_VERSION_H
21 #ifdef HAVE_GNU_GET_LIBC_VERSION
22 #define CHECK_LIBC_VERSION
23 #endif
24 #endif
26 #define STR_IMPL(x) #x
27 #define STR(x) STR_IMPL(x)
29 /** Return the name of the compile time libc. Returns NULL if we
30 * cannot identify the libc. */
31 const char *
32 tor_libc_get_name(void)
34 #ifdef __GLIBC__
35 return "Glibc";
36 #else /* !defined(__GLIBC__) */
37 return NULL;
38 #endif /* defined(__GLIBC__) */
41 /** Return a string representation of the version of the currently running
42 * version of Glibc. */
43 const char *
44 tor_libc_get_version_str(void)
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) */
56 /** Return a string representation of the version of Glibc that was used at
57 * compilation time. */
58 const char *
59 tor_libc_get_header_version_str(void)
61 #ifdef __GLIBC__
62 return STR(__GLIBC__) "." STR(__GLIBC_MINOR__);
63 #else
64 return "N/A";
65 #endif /* defined(__GLIBC__) */