|
25 | 25 | */ |
26 | 26 | #include "postgres.h" |
27 | 27 |
|
| 28 | +#ifdef USE_ICU |
| 29 | +#include <unicode/uchar.h> |
| 30 | +#endif |
| 31 | + |
| 32 | +#ifdef __GLIBC__ |
| 33 | +#include <gnu/libc-version.h> |
| 34 | +#endif |
| 35 | + |
28 | 36 | #include "funcapi.h" |
29 | 37 | #include "utils/builtins.h" |
30 | 38 | #include "utils/hsearch.h" |
@@ -66,6 +74,70 @@ add_system_version(const char *name, SystemVersionCB cb, VersionType type) |
66 | 74 | hentry->type = type; |
67 | 75 | } |
68 | 76 |
|
| 77 | +static const char * |
| 78 | +core_get_version(bool *available) |
| 79 | +{ |
| 80 | + *available = true; |
| 81 | + return (const char *) psprintf("%s", PG_VERSION); |
| 82 | +} |
| 83 | + |
| 84 | +static const char * |
| 85 | +core_get_arch(bool *available) |
| 86 | +{ |
| 87 | + *available = true; |
| 88 | + return (const char *) psprintf("%s", PG_ARCH_STR); |
| 89 | +} |
| 90 | + |
| 91 | +static const char * |
| 92 | +core_get_compiler(bool *available) |
| 93 | +{ |
| 94 | + *available = true; |
| 95 | + return (const char *) psprintf("%s", PG_CC_STR); |
| 96 | +} |
| 97 | + |
| 98 | +#ifdef USE_ICU |
| 99 | +static const char * |
| 100 | +icu_get_version(bool *available) |
| 101 | +{ |
| 102 | + UVersionInfo UCDVersion; |
| 103 | + char *version = palloc0(U_MAX_VERSION_STRING_LENGTH); |
| 104 | + |
| 105 | + *available = true; |
| 106 | + u_getUnicodeVersion(UCDVersion); |
| 107 | + u_versionToString(UCDVersion, version); |
| 108 | + return (const char *) version; |
| 109 | +} |
| 110 | +#endif |
| 111 | + |
| 112 | +#ifdef __GLIBC__ |
| 113 | +static const char * |
| 114 | +glibc_get_version(bool *available) |
| 115 | +{ |
| 116 | + *available = true; |
| 117 | + return (const char *) gnu_get_libc_version(); |
| 118 | +} |
| 119 | +#endif |
| 120 | + |
| 121 | +/* |
| 122 | + * Register versions that describe core components and do not correspond to any |
| 123 | + * individual component. |
| 124 | + */ |
| 125 | +void |
| 126 | +register_core_versions() |
| 127 | +{ |
| 128 | + add_system_version("Core", core_get_version, CompileTime); |
| 129 | + add_system_version("Arch", core_get_arch, CompileTime); |
| 130 | + add_system_version("Compiler", core_get_compiler, CompileTime); |
| 131 | + |
| 132 | +#ifdef USE_ICU |
| 133 | + add_system_version("ICU", icu_get_version, RunTime); |
| 134 | +#endif |
| 135 | + |
| 136 | +#ifdef __GLIBC__ |
| 137 | + add_system_version("Glibc", glibc_get_version, RunTime); |
| 138 | +#endif |
| 139 | +} |
| 140 | + |
69 | 141 | /* |
70 | 142 | * pg_get_system_versions |
71 | 143 | * |
|
0 commit comments