1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "common/linux/linux_libc_support.h"
7 #include "linux_utils.h"
9 bool ElfFileSoVersion(const char* mapping_name
, uint32_t* version_components
) {
10 if (!version_components
) {
14 // We found no version so just report 0
15 const char* so_version
= my_strstr(mapping_name
, ".so.");
16 if (so_version
== nullptr) {
20 char tmp
[12]; // 11 for maximum representation of UINT32T_MAX + \0 ?
21 size_t current_position
= 0;
24 for (size_t so_version_pos
= 0; so_version_pos
<= my_strlen(so_version
);
26 // We can't have more than four: MAJOR.minor.release.patch
27 if (current_position
== 4) {
31 char c
= so_version
[so_version_pos
];
33 if ((c
<= '9' && c
>= '0')) {
35 tmp
[next_tmp
+ 1] = '\0';
39 if (so_version
[so_version_pos
+ 1] != '\0') {
44 if (my_strlen(tmp
) > 0) {
46 if (!my_strtoui(&t
, tmp
)) {
49 uint32_t casted_tmp
= (uint32_t)t
;
50 version_components
[current_position
] = casted_tmp
;