aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-07-20 16:37:11 -0400
committerNick Mathewson <nickm@torproject.org>2020-07-20 16:37:11 -0400
commitd6570eaf5d8690799a1b698552315372fae2e1f0 (patch)
tree5e8824c24ce4c1e40b2071686531f0432bb00c25 /src/lib
parentb18e2749191dd261462d12a315cd79fcbbccbefa (diff)
parent29307c0625fd6a95080d341b15646a4cd55b4178 (diff)
downloadtor-d6570eaf5d8690799a1b698552315372fae2e1f0.tar.gz
tor-d6570eaf5d8690799a1b698552315372fae2e1f0.zip
Merge remote-tracking branch 'tor-gitlab/mr/59'
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/osinfo/include.am6
-rw-r--r--src/lib/osinfo/libc.c66
-rw-r--r--src/lib/osinfo/libc.h19
3 files changed, 89 insertions, 2 deletions
diff --git a/src/lib/osinfo/include.am b/src/lib/osinfo/include.am
index 84bd7feb00..df8c98500c 100644
--- a/src/lib/osinfo/include.am
+++ b/src/lib/osinfo/include.am
@@ -7,7 +7,8 @@ endif
# ADD_C_FILE: INSERT SOURCES HERE.
src_lib_libtor_osinfo_a_SOURCES = \
- src/lib/osinfo/uname.c
+ src/lib/osinfo/uname.c \
+ src/lib/osinfo/libc.c
src_lib_libtor_osinfo_testing_a_SOURCES = \
$(src_lib_libtor_osinfo_a_SOURCES)
@@ -16,4 +17,5 @@ src_lib_libtor_osinfo_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
# ADD_C_FILE: INSERT HEADERS HERE.
noinst_HEADERS += \
- src/lib/osinfo/uname.h
+ src/lib/osinfo/uname.h \
+ src/lib/osinfo/libc.h
diff --git a/src/lib/osinfo/libc.c b/src/lib/osinfo/libc.c
new file mode 100644
index 0000000000..32cbad0fa2
--- /dev/null
+++ b/src/lib/osinfo/libc.c
@@ -0,0 +1,66 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2020, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file libc.c
+ * @brief Functions to get the name and version of the system libc.
+ **/
+
+#include "orconfig.h"
+#include "lib/osinfo/libc.h"
+#include <stdlib.h>
+
+#ifdef HAVE_GNU_LIBC_VERSION_H
+#include <gnu/libc-version.h>
+#endif
+
+#ifdef HAVE_GNU_LIBC_VERSION_H
+#ifdef HAVE_GNU_GET_LIBC_VERSION
+#define CHECK_LIBC_VERSION
+#endif
+#endif
+
+#define STR_IMPL(x) #x
+#define STR(x) STR_IMPL(x)
+
+/** Return the name of the compile time libc. Returns NULL if we
+ * cannot identify the libc. */
+const char *
+tor_libc_get_name(void)
+{
+#ifdef __GLIBC__
+ return "Glibc";
+#else /* !defined(__GLIBC__) */
+ return NULL;
+#endif /* defined(__GLIBC__) */
+}
+
+/** Return a string representation of the version of the currently running
+ * version of Glibc. */
+const char *
+tor_libc_get_version_str(void)
+{
+#ifdef CHECK_LIBC_VERSION
+ const char *version = gnu_get_libc_version();
+ if (version == NULL)
+ return "N/A";
+ return version;
+#else /* !defined(CHECK_LIBC_VERSION) */
+ return "N/A";
+#endif /* defined(CHECK_LIBC_VERSION) */
+}
+
+/** Return a string representation of the version of Glibc that was used at
+ * compilation time. */
+const char *
+tor_libc_get_header_version_str(void)
+{
+#ifdef __GLIBC__
+ return STR(__GLIBC__) "." STR(__GLIBC_MINOR__);
+#else
+ return "N/A";
+#endif /* defined(__GLIBC__) */
+}
diff --git a/src/lib/osinfo/libc.h b/src/lib/osinfo/libc.h
new file mode 100644
index 0000000000..f4303f8c9c
--- /dev/null
+++ b/src/lib/osinfo/libc.h
@@ -0,0 +1,19 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2020, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file libc.h
+ * @brief Header for lib/osinfo/libc.c
+ **/
+
+#ifndef TOR_LIB_OSINFO_LIBC_H
+#define TOR_LIB_OSINFO_LIBC_H
+
+const char *tor_libc_get_name(void);
+const char *tor_libc_get_version_str(void);
+const char *tor_libc_get_header_version_str(void);
+
+#endif /* !defined(TOR_LIB_OSINFO_LIBC_H) */